github.com/Finschia/finschia-sdk@v0.48.1/server/rosetta/lib/types/types.go (about) 1 package types 2 3 import ( 4 "context" 5 6 "github.com/coinbase/rosetta-sdk-go/server" 7 "github.com/coinbase/rosetta-sdk-go/types" 8 ) 9 10 // SpecVersion defines the specification of rosetta 11 const SpecVersion = "" 12 13 // NetworkInformationProvider defines the interface used to provide information regarding 14 // the network and the version of the cosmos sdk used 15 type NetworkInformationProvider interface { 16 // SupportedOperations lists the operations supported by the implementation 17 SupportedOperations() []string 18 // OperationStatuses returns the list of statuses supported by the implementation 19 OperationStatuses() []*types.OperationStatus 20 // Version returns the version of the node 21 Version() string 22 } 23 24 // Client defines the API the client implementation should provide. 25 type Client interface { 26 // Bootstrap Needed if the client needs to perform some action before connecting. 27 Bootstrap() error 28 // Ready checks if the servicer constraints for queries are satisfied 29 // for example the node might still not be ready, it's useful in process 30 // when the rosetta instance might come up before the node itself 31 // the servicer must return nil if the node is ready 32 Ready() error 33 34 // Data API 35 36 // Balances fetches the balance of the given address 37 // if height is not nil, then the balance will be displayed 38 // at the provided height, otherwise last block balance will be returned 39 Balances(ctx context.Context, addr string, height *int64) ([]*types.Amount, error) 40 // BlockByHash gets a block and its transaction at the provided height 41 BlockByHash(ctx context.Context, hash string) (BlockResponse, error) 42 // BlockByHeight gets a block given its height, if height is nil then last block is returned 43 BlockByHeight(ctx context.Context, height *int64) (BlockResponse, error) 44 // BlockTransactionsByHash gets the block, parent block and transactions 45 // given the block hash. 46 BlockTransactionsByHash(ctx context.Context, hash string) (BlockTransactionsResponse, error) 47 // BlockTransactionsByHeight gets the block, parent block and transactions 48 // given the block hash. 49 BlockTransactionsByHeight(ctx context.Context, height *int64) (BlockTransactionsResponse, error) 50 // GetTx gets a transaction given its hash 51 GetTx(ctx context.Context, hash string) (*types.Transaction, error) 52 // GetUnconfirmedTx gets an unconfirmed Tx given its hash 53 // NOTE(fdymylja): NOT IMPLEMENTED YET! 54 GetUnconfirmedTx(ctx context.Context, hash string) (*types.Transaction, error) 55 // Mempool returns the list of the current non confirmed transactions 56 Mempool(ctx context.Context) ([]*types.TransactionIdentifier, error) 57 // Peers gets the peers currently connected to the node 58 Peers(ctx context.Context) ([]*types.Peer, error) 59 // Status returns the node status, such as sync data, version etc 60 Status(ctx context.Context) (*types.SyncStatus, error) 61 62 // Construction API 63 64 // PostTx posts txBytes to the node and returns the transaction identifier plus metadata related 65 // to the transaction itself. 66 PostTx(txBytes []byte) (res *types.TransactionIdentifier, meta map[string]interface{}, err error) 67 // ConstructionMetadataFromOptions builds metadata map from an option map 68 ConstructionMetadataFromOptions(ctx context.Context, options map[string]interface{}) (meta map[string]interface{}, err error) 69 OfflineClient 70 } 71 72 // OfflineClient defines the functionalities supported without having access to the node 73 type OfflineClient interface { 74 NetworkInformationProvider 75 // SignedTx returns the signed transaction given the tx bytes (msgs) plus the signatures 76 SignedTx(ctx context.Context, txBytes []byte, sigs []*types.Signature) (signedTxBytes []byte, err error) 77 // TxOperationsAndSignersAccountIdentifiers returns the operations related to a transaction and the account 78 // identifiers if the transaction is signed 79 TxOperationsAndSignersAccountIdentifiers(signed bool, hexBytes []byte) (ops []*types.Operation, signers []*types.AccountIdentifier, err error) 80 // ConstructionPayload returns the construction payload given the request 81 ConstructionPayload(ctx context.Context, req *types.ConstructionPayloadsRequest) (resp *types.ConstructionPayloadsResponse, err error) 82 // PreprocessOperationsToOptions returns the options given the preprocess operations 83 PreprocessOperationsToOptions(ctx context.Context, req *types.ConstructionPreprocessRequest) (resp *types.ConstructionPreprocessResponse, err error) 84 // AccountIdentifierFromPublicKey returns the account identifier given the public key 85 AccountIdentifierFromPublicKey(pubKey *types.PublicKey) (*types.AccountIdentifier, error) 86 } 87 88 type BlockTransactionsResponse struct { 89 BlockResponse 90 Transactions []*types.Transaction 91 } 92 93 type BlockResponse struct { 94 Block *types.BlockIdentifier 95 ParentBlock *types.BlockIdentifier 96 MillisecondTimestamp int64 97 TxCount int64 98 } 99 100 // API defines the exposed APIs 101 // if the service is online 102 type API interface { 103 DataAPI 104 ConstructionAPI 105 } 106 107 // DataAPI defines the full data API implementation 108 type DataAPI interface { 109 server.NetworkAPIServicer 110 server.AccountAPIServicer 111 server.BlockAPIServicer 112 server.MempoolAPIServicer 113 } 114 115 var _ server.ConstructionAPIServicer = ConstructionAPI(nil) 116 117 // ConstructionAPI defines the full construction API with 118 // the online and offline endpoints 119 type ConstructionAPI interface { 120 ConstructionOnlineAPI 121 ConstructionOfflineAPI 122 } 123 124 // ConstructionOnlineAPI defines the construction methods 125 // allowed in an online implementation 126 type ConstructionOnlineAPI interface { 127 ConstructionMetadata( 128 context.Context, 129 *types.ConstructionMetadataRequest, 130 ) (*types.ConstructionMetadataResponse, *types.Error) 131 ConstructionSubmit( 132 context.Context, 133 *types.ConstructionSubmitRequest, 134 ) (*types.TransactionIdentifierResponse, *types.Error) 135 } 136 137 // ConstructionOfflineAPI defines the construction methods 138 // allowed 139 type ConstructionOfflineAPI interface { 140 ConstructionCombine( 141 context.Context, 142 *types.ConstructionCombineRequest, 143 ) (*types.ConstructionCombineResponse, *types.Error) 144 ConstructionDerive( 145 context.Context, 146 *types.ConstructionDeriveRequest, 147 ) (*types.ConstructionDeriveResponse, *types.Error) 148 ConstructionHash( 149 context.Context, 150 *types.ConstructionHashRequest, 151 ) (*types.TransactionIdentifierResponse, *types.Error) 152 ConstructionParse( 153 context.Context, 154 *types.ConstructionParseRequest, 155 ) (*types.ConstructionParseResponse, *types.Error) 156 ConstructionPayloads( 157 context.Context, 158 *types.ConstructionPayloadsRequest, 159 ) (*types.ConstructionPayloadsResponse, *types.Error) 160 ConstructionPreprocess( 161 context.Context, 162 *types.ConstructionPreprocessRequest, 163 ) (*types.ConstructionPreprocessResponse, *types.Error) 164 }