testnet
GitHub EN

ExportAppStateAndValidators

ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error)

현재 블록 높이에서 전체 애플리케이션 상태와 검증인 집합을 genesis.json 파일에 적합한 형식으로 내보냅니다. 이 함수는 네트워크 업그레이드, 하드 포크, 그리고 기존 상태에서 새로운 테스트넷을 생성하는 데 매우 중요합니다. 등록된 모든 모듈을 순회하며 각 모듈의 ExportGenesis 메서드를 호출하고 그 결과를 집계합니다.

파라미터

이름 타입 필수 설명
forZeroHeight bool true인 경우, 높이 0에서 시작하는 새로운 체인을 위해 상태를 준비합니다. 여기에는 모든 스테이킹 보상을 인출하는 것과 같은 특별한 처리가 포함됩니다.
jailAllowedAddrs []string 내보낸 상태에서 감옥에 갇히는 것이 허용된 검증인 주소 목록입니다. 비어 있으면 어떤 검증인도 감옥에 갇히지 않습니다.
modulesToExport []string 내보낼 모듈 이름 목록입니다. 비어 있으면 모든 모듈이 내보내집니다.

반환값

타입: servertypes.ExportedApp

JSON으로 마샬링된 앱 상태, 검증인 목록, 내보내기 높이, 그리고 합의 파라미터를 포함하는 ExportedApp 구조체입니다.

에러

코드 이름 설명
error Export Error 모듈이 제네시스 상태를 내보내는 데 실패하거나 최종 상태를 JSON으로 마샬링할 수 없는 경우 오류를 반환합니다.

예제

네트워크 업그레이드를 위한 상태 내보내기

이 개념적 예제는 `marood export`와 같은 CLI 명령 내에서 `ExportAppStateAndValidators`가 어떻게 호출되는지를 보여줍니다. 현재 블록 높이를 보존하는 표준 상태 내보내기를 위해 `forZeroHeight=false`로 함수가 호출됩니다.

// This function is typically called from a CLI command, not directly in application code.
// Example of how it might be used in a command:

// marood export --for-zero-height=false > genesis_export.json

func exportStateCmd() *cobra.Command {
    cmd := &cobra.Command{
        Use:   "export",
        Short: "Export state to JSON",
        RunE: func(cmd *cobra.Command, args []string) error {
            serverCtx := server.GetServerContextFromCmd(cmd)
            app := serverCtx.App.(servertypes.Application)

            // Assume 'marooApp' is the concrete type of our application
            marooApp, ok := app.(*maroo.MarooApp)
            if !ok {
                return fmt.Errorf("application is not a MarooApp")
            }

            exportedApp, err := marooApp.ExportAppStateAndValidators(false, []string{}, []string{})
            if err != nil {
                return err
            }

            // The result is then typically printed to stdout
            fmt.Println(string(exportedApp.AppState))
            return nil
        },
    }
    return cmd
}
ESC
검색어를 입력하세요