github.com/Finschia/finschia-sdk@v0.48.1/server/rosetta/types.go (about)

     1  package rosetta
     2  
     3  import (
     4  	"crypto/sha256"
     5  )
     6  
     7  // statuses
     8  const (
     9  	StatusTxSuccess   = "Success"
    10  	StatusTxReverted  = "Reverted"
    11  	StatusPeerSynced  = "synced"
    12  	StatusPeerSyncing = "syncing"
    13  )
    14  
    15  // In rosetta all state transitions must be represented as transactions
    16  // since in tendermint begin block and end block are state transitions
    17  // which are not represented as transactions we mock only the balance changes
    18  // happening at those levels as transactions. (check BeginBlockTxHash for more info)
    19  const (
    20  	DeliverTxSize       = sha256.Size
    21  	BeginEndBlockTxSize = DeliverTxSize + 1
    22  	EndBlockHashStart   = 0x0
    23  	BeginBlockHashStart = 0x1
    24  )
    25  
    26  const (
    27  	// BurnerAddressIdentifier mocks the account identifier of a burner address
    28  	// all coins burned in the sdk will be sent to this identifier, which per sdk.AccAddress
    29  	// design we will never be able to query (as of now).
    30  	// Rosetta does not understand supply contraction.
    31  	BurnerAddressIdentifier = "burner"
    32  )
    33  
    34  // TransactionType is used to distinguish if a rosetta provided hash
    35  // represents endblock, beginblock or deliver tx
    36  type TransactionType int
    37  
    38  const (
    39  	UnrecognizedTx TransactionType = iota
    40  	BeginBlockTx
    41  	EndBlockTx
    42  	DeliverTxTx
    43  )
    44  
    45  // metadata options
    46  
    47  // misc
    48  const (
    49  	Log = "log"
    50  )
    51  
    52  // ConstructionPreprocessMetadata is used to represent
    53  // the metadata rosetta can provide during preprocess options
    54  type ConstructionPreprocessMetadata struct {
    55  	Memo     string `json:"memo"`
    56  	GasLimit uint64 `json:"gas_limit"`
    57  	GasPrice string `json:"gas_price"`
    58  }
    59  
    60  func (c *ConstructionPreprocessMetadata) FromMetadata(meta map[string]interface{}) error {
    61  	return unmarshalMetadata(meta, c)
    62  }
    63  
    64  // PreprocessOperationsOptionsResponse is the structured metadata options returned by the preprocess operations endpoint
    65  type PreprocessOperationsOptionsResponse struct {
    66  	ExpectedSigners []string `json:"expected_signers"`
    67  	Memo            string   `json:"memo"`
    68  	GasLimit        uint64   `json:"gas_limit"`
    69  	GasPrice        string   `json:"gas_price"`
    70  }
    71  
    72  func (c PreprocessOperationsOptionsResponse) ToMetadata() (map[string]interface{}, error) {
    73  	return marshalMetadata(c)
    74  }
    75  
    76  func (c *PreprocessOperationsOptionsResponse) FromMetadata(meta map[string]interface{}) error {
    77  	return unmarshalMetadata(meta, c)
    78  }
    79  
    80  // SignerData contains information on the signers when the request
    81  // is being created, used to populate the account information
    82  type SignerData struct {
    83  	AccountNumber uint64 `json:"account_number"`
    84  	Sequence      uint64 `json:"sequence"`
    85  }
    86  
    87  // ConstructionMetadata are the metadata options used to
    88  // construct a transaction. It is returned by ConstructionMetadataFromOptions
    89  // and fed to ConstructionPayload to process the bytes to sign.
    90  type ConstructionMetadata struct {
    91  	ChainID     string        `json:"chain_id"`
    92  	SignersData []*SignerData `json:"signer_data"`
    93  	GasLimit    uint64        `json:"gas_limit"`
    94  	GasPrice    string        `json:"gas_price"`
    95  	Memo        string        `json:"memo"`
    96  }
    97  
    98  func (c ConstructionMetadata) ToMetadata() (map[string]interface{}, error) {
    99  	return marshalMetadata(c)
   100  }
   101  
   102  func (c *ConstructionMetadata) FromMetadata(meta map[string]interface{}) error {
   103  	return unmarshalMetadata(meta, c)
   104  }