github.com/turingchain2020/turingchain@v1.1.21/rpc/types/types.go (about)

     1  // Copyright Turing Corp. 2018 All Rights Reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package types rpc相关的一些结构体定义以及转化函数
     6  package types
     7  
     8  import (
     9  	"encoding/json"
    10  )
    11  
    12  // TransParm transport parameter
    13  type TransParm struct {
    14  	Execer    string     `json:"execer"`
    15  	Payload   string     `json:"payload"`
    16  	Signature *Signature `json:"signature"`
    17  	Fee       int64      `json:"fee"`
    18  }
    19  
    20  // SignedTx signature tx
    21  type SignedTx struct {
    22  	Unsign string `json:"unsignTx"`
    23  	Sign   string `json:"sign"`
    24  	Pubkey string `json:"pubkey"`
    25  	Ty     int32  `json:"ty"`
    26  }
    27  
    28  // RawParm defines raw parameter command
    29  type RawParm struct {
    30  	Token string `json:"token"`
    31  	Data  string `json:"data"`
    32  }
    33  
    34  // QueryParm Query parameter
    35  type QueryParm struct {
    36  	Hash string `json:"hash"`
    37  }
    38  
    39  // BlockParam block parameter
    40  type BlockParam struct {
    41  	Start    int64 `json:"start"`
    42  	End      int64 `json:"end"`
    43  	Isdetail bool  `json:"isDetail"`
    44  }
    45  
    46  // Header header parameter
    47  type Header struct {
    48  	Version    int64      `json:"version"`
    49  	ParentHash string     `json:"parentHash"`
    50  	TxHash     string     `json:"txHash"`
    51  	StateHash  string     `json:"stateHash"`
    52  	Height     int64      `json:"height"`
    53  	BlockTime  int64      `json:"blockTime"`
    54  	TxCount    int64      `json:"txCount"`
    55  	Hash       string     `json:"hash"`
    56  	Difficulty uint32     `json:"difficulty"`
    57  	Signature  *Signature `json:"signature,omitempty"`
    58  }
    59  
    60  // Signature parameter
    61  type Signature struct {
    62  	Ty        int32  `json:"ty"`
    63  	Pubkey    string `json:"pubkey"`
    64  	Signature string `json:"signature"`
    65  }
    66  
    67  // Transaction parameter
    68  type Transaction struct {
    69  	Execer     string          `json:"execer"`
    70  	Payload    json.RawMessage `json:"payload"`
    71  	RawPayload string          `json:"rawPayload"`
    72  	Signature  *Signature      `json:"signature"`
    73  	Fee        int64           `json:"fee"`
    74  	FeeFmt     string          `json:"feefmt"`
    75  	Expire     int64           `json:"expire"`
    76  	Nonce      int64           `json:"nonce"`
    77  	From       string          `json:"from,omitempty"`
    78  	To         string          `json:"to"`
    79  	Amount     int64           `json:"amount,omitempty"`
    80  	AmountFmt  string          `json:"amountfmt,omitempty"`
    81  	GroupCount int32           `json:"groupCount,omitempty"`
    82  	Header     string          `json:"header,omitempty"`
    83  	Next       string          `json:"next,omitempty"`
    84  	Hash       string          `json:"hash,omitempty"`
    85  	ChainID    int32           `json:"chainID,omitempty"`
    86  }
    87  
    88  // ReceiptLog defines receipt log command
    89  type ReceiptLog struct {
    90  	Ty  int32  `json:"ty"`
    91  	Log string `json:"log"`
    92  }
    93  
    94  // ReceiptData defines receipt data rpc command
    95  type ReceiptData struct {
    96  	Ty   int32         `json:"ty"`
    97  	Logs []*ReceiptLog `json:"logs"`
    98  }
    99  
   100  // ReceiptDataResult receipt data result
   101  type ReceiptDataResult struct {
   102  	Ty     int32               `json:"ty"`
   103  	TyName string              `json:"tyName"`
   104  	Logs   []*ReceiptLogResult `json:"logs"`
   105  }
   106  
   107  // ReceiptLogResult receipt log result
   108  type ReceiptLogResult struct {
   109  	Ty     int32           `json:"ty"`
   110  	TyName string          `json:"tyName"`
   111  	Log    json.RawMessage `json:"log"`
   112  	RawLog string          `json:"rawLog"`
   113  }
   114  
   115  // Block block information
   116  type Block struct {
   117  	Version    int64          `json:"version"`
   118  	ParentHash string         `json:"parentHash"`
   119  	TxHash     string         `json:"txHash"`
   120  	StateHash  string         `json:"stateHash"`
   121  	Height     int64          `json:"height"`
   122  	BlockTime  int64          `json:"blockTime"`
   123  	Txs        []*Transaction `json:"txs"`
   124  	Difficulty uint32         ` json:"difficulty,omitempty"`
   125  	MainHash   string         ` json:"mainHash,omitempty"`
   126  	MainHeight int64          `json:"mainHeight,omitempty"`
   127  	Signature  *Signature     `json:"signature,omitempty"`
   128  }
   129  
   130  // BlockDetail  block detail
   131  type BlockDetail struct {
   132  	Block    *Block               `json:"block"`
   133  	Receipts []*ReceiptDataResult `json:"recipts"`
   134  }
   135  
   136  // BlockDetails block details
   137  type BlockDetails struct {
   138  	Items []*BlockDetail `json:"items"`
   139  }
   140  
   141  // Asset asset
   142  type Asset struct {
   143  	Exec   string `json:"exec"`
   144  	Symbol string `json:"symbol"`
   145  	Amount int64  `json:"amount"`
   146  }
   147  
   148  // TransactionDetail transaction detail
   149  type TransactionDetail struct {
   150  	Tx         *Transaction       `json:"tx"`
   151  	Receipt    *ReceiptDataResult `json:"receipt"`
   152  	Proofs     []string           `json:"proofs"`
   153  	Height     int64              `json:"height"`
   154  	Index      int64              `json:"index"`
   155  	Blocktime  int64              `json:"blockTime"`
   156  	Amount     int64              `json:"amount"`
   157  	Fromaddr   string             `json:"fromAddr"`
   158  	ActionName string             `json:"actionName"`
   159  	Assets     []*Asset           `json:"assets"`
   160  	TxProofs   []*TxProof         `json:"txProofs"`
   161  	FullHash   string             `json:"fullHash"`
   162  }
   163  
   164  // TxProof :
   165  type TxProof struct {
   166  	Proofs   []string `json:"proofs"`
   167  	Index    uint32   `json:"index"`
   168  	RootHash string   `json:"rootHash"`
   169  }
   170  
   171  // ReplyTxInfos reply tx infos
   172  type ReplyTxInfos struct {
   173  	TxInfos []*ReplyTxInfo `json:"txInfos"`
   174  }
   175  
   176  // ReplyTxInfo reply tx information
   177  type ReplyTxInfo struct {
   178  	Hash   string   `json:"hash"`
   179  	Height int64    `json:"height"`
   180  	Index  int64    `json:"index"`
   181  	Assets []*Asset `json:"assets"`
   182  }
   183  
   184  // TransactionDetails transaction details
   185  type TransactionDetails struct {
   186  	//Txs []*Transaction `json:"txs"`
   187  	Txs []*TransactionDetail `json:"txs"`
   188  }
   189  
   190  // ReplyTxList reply tx list
   191  type ReplyTxList struct {
   192  	Txs []*Transaction `json:"txs"`
   193  }
   194  
   195  // ReplyProperFee reply proper fee
   196  type ReplyProperFee struct {
   197  	ProperFee int64 `json:"properFee"`
   198  }
   199  
   200  // ReplyHash reply hash string json
   201  type ReplyHash struct {
   202  	Hash string `json:"hash"`
   203  }
   204  
   205  // ReplyHashes reply hashes
   206  type ReplyHashes struct {
   207  	Hashes []string `json:"hashes"`
   208  }
   209  
   210  // PeerList peer list
   211  type PeerList struct {
   212  	Peers []*Peer `json:"peers"`
   213  }
   214  
   215  // Peer  information
   216  type Peer struct {
   217  	Addr           string  `json:"addr"`
   218  	Port           int32   `json:"port"`
   219  	Name           string  `json:"name"`
   220  	MempoolSize    int32   `json:"mempoolSize"`
   221  	Self           bool    `json:"self"`
   222  	Header         *Header `json:"header"`
   223  	Version        string  `json:"version,omitempty"`
   224  	LocalDBVersion string  `json:"localDBVersion,omitempty"`
   225  	StoreDBVersion string  `json:"storeDBVersion,omitempty"`
   226  }
   227  
   228  // WalletAccounts Wallet Module
   229  type WalletAccounts struct {
   230  	Wallets []*WalletAccount `json:"wallets"`
   231  }
   232  
   233  // WalletAccount  wallet account
   234  type WalletAccount struct {
   235  	Acc   *Account `json:"acc"`
   236  	Label string   `json:"label"`
   237  }
   238  
   239  // Account account information
   240  type Account struct {
   241  	Currency int32  `json:"currency"`
   242  	Balance  int64  `json:"balance"`
   243  	Frozen   int64  `json:"frozen"`
   244  	Addr     string `json:"addr"`
   245  }
   246  
   247  // Reply info
   248  type Reply struct {
   249  	IsOk bool   `json:"isOK"`
   250  	Msg  string `json:"msg"`
   251  }
   252  
   253  // Headers defines headers rpc command
   254  type Headers struct {
   255  	Items []*Header `json:"items"`
   256  }
   257  
   258  // ReqAddr require address
   259  type ReqAddr struct {
   260  	Addr string `json:"addr"`
   261  }
   262  
   263  // ReqHashes require hashes
   264  type ReqHashes struct {
   265  	Hashes        []string `json:"hashes"`
   266  	DisableDetail bool     `json:"disableDetail"`
   267  }
   268  
   269  // ReqWalletTransactionList require wallet transaction list
   270  type ReqWalletTransactionList struct {
   271  	FromTx    string `json:"fromTx"`
   272  	Count     int32  `json:"count"`
   273  	Direction int32  `json:"direction"`
   274  }
   275  
   276  // WalletTxDetails wallet tx details
   277  type WalletTxDetails struct {
   278  	TxDetails []*WalletTxDetail `json:"txDetails"`
   279  }
   280  
   281  // WalletTxDetail wallet tx detail
   282  type WalletTxDetail struct {
   283  	Tx         *Transaction       `json:"tx"`
   284  	Receipt    *ReceiptDataResult `json:"receipt"`
   285  	Height     int64              `json:"height"`
   286  	Index      int64              `json:"index"`
   287  	BlockTime  int64              `json:"blockTime"`
   288  	Amount     int64              `json:"amount"`
   289  	FromAddr   string             `json:"fromAddr"`
   290  	TxHash     string             `json:"txHash"`
   291  	ActionName string             `json:"actionName"`
   292  }
   293  
   294  // BlockOverview block overview
   295  type BlockOverview struct {
   296  	Head     *Header  `json:"head"`
   297  	TxCount  int64    `json:"txCount"`
   298  	TxHashes []string `json:"txHashes"`
   299  }
   300  
   301  // Query4Jrpc query jrpc
   302  type Query4Jrpc struct {
   303  	Execer   string          `json:"execer"`
   304  	FuncName string          `json:"funcName"`
   305  	Payload  json.RawMessage `json:"payload"`
   306  }
   307  
   308  // ChainExecutor chain executor
   309  type ChainExecutor struct {
   310  	Driver    string          `json:"execer"`
   311  	FuncName  string          `json:"funcName"`
   312  	StateHash string          `json:"stateHash"`
   313  	Payload   json.RawMessage `json:"payload"`
   314  }
   315  
   316  // WalletStatus wallet status
   317  type WalletStatus struct {
   318  	IsWalletLock bool `json:"isWalletLock"`
   319  	IsAutoMining bool `json:"isAutoMining"`
   320  	IsHasSeed    bool `json:"isHasSeed"`
   321  	IsTicketLock bool `json:"isTicketLock"`
   322  }
   323  
   324  // NodeNetinfo node net info
   325  type NodeNetinfo struct {
   326  	Externaladdr string `json:"externalAddr"`
   327  	Localaddr    string `json:"localAddr"`
   328  	Service      bool   `json:"service"`
   329  	Outbounds    int32  `json:"outbounds"`
   330  	Inbounds     int32  `json:"inbounds"`
   331  	Routingtable int32  `json:"routingtable"`
   332  	Peerstore    int32  `json:"peerstore"`
   333  	Ratein       string `json:"ratein"`
   334  	Rateout      string `json:"rateout"`
   335  	Ratetotal    string `json:"ratetotal"`
   336  }
   337  
   338  // ReplyCacheTxList reply cache tx list
   339  type ReplyCacheTxList struct {
   340  	Txs []*Transaction `json:"txs,omitempty"`
   341  }
   342  
   343  // TimeStatus time status
   344  type TimeStatus struct {
   345  	NtpTime   string `json:"ntpTime"`
   346  	LocalTime string `json:"localTime"`
   347  	Diff      int64  `json:"diff"`
   348  }
   349  
   350  // ReplyBlkSeqs reply block sequences
   351  type ReplyBlkSeqs struct {
   352  	BlkSeqInfos []*ReplyBlkSeq `json:"blkseqInfos"`
   353  }
   354  
   355  // ReplyBlkSeq reply block sequece
   356  type ReplyBlkSeq struct {
   357  	Hash string `json:"hash"`
   358  	Type int64  `json:"type"`
   359  }
   360  
   361  // CreateTxIn create tx input
   362  type CreateTxIn struct {
   363  	Execer     string          `json:"execer"`
   364  	ActionName string          `json:"actionName"`
   365  	Payload    json.RawMessage `json:"payload"`
   366  }
   367  
   368  // AllExecBalance all exec balance
   369  type AllExecBalance struct {
   370  	Addr        string         `json:"addr"`
   371  	ExecAccount []*ExecAccount `json:"execAccount"`
   372  }
   373  
   374  // ExecAccount exec account
   375  type ExecAccount struct {
   376  	Execer  string   `json:"execer"`
   377  	Account *Account `json:"account"`
   378  }
   379  
   380  // ExecNameParm exec name parameter
   381  type ExecNameParm struct {
   382  	ExecName string `json:"execname"`
   383  }
   384  
   385  //CreateTx 为了简化Note 的创建过程,在json rpc 中,note 采用string 格式
   386  type CreateTx struct {
   387  	To          string `json:"to,omitempty"`
   388  	Amount      int64  `json:"amount,omitempty"`
   389  	Fee         int64  `json:"fee,omitempty"`
   390  	Note        string `json:"note,omitempty"`
   391  	IsWithdraw  bool   `json:"isWithdraw,omitempty"`
   392  	IsToken     bool   `json:"isToken,omitempty"`
   393  	TokenSymbol string `json:"tokenSymbol,omitempty"`
   394  	ExecName    string `json:"execName,omitempty"` //TransferToExec and Withdraw 的执行器
   395  	Execer      string `json:"execer,omitempty"`   //执行器名称
   396  }
   397  
   398  // ReWriteRawTx parameter
   399  type ReWriteRawTx struct {
   400  	Tx     string `json:"tx"`
   401  	To     string `json:"to"`
   402  	Fee    int64  `json:"fee"`
   403  	Expire string `json:"expire"`
   404  	Index  int32  `json:"index"`
   405  }
   406  
   407  //BlockSeq parameter
   408  type BlockSeq struct {
   409  	Num    int64          `json:"num,omitempty"`
   410  	Seq    *BlockSequence `json:"seq,omitempty"`
   411  	Detail *BlockDetail   `json:"detail,omitempty"`
   412  }
   413  
   414  //BlockSequence parameter
   415  type BlockSequence struct {
   416  	Hash string `json:"hash,omitempty"`
   417  	Type int64  `json:"type,omitempty"`
   418  }
   419  
   420  //ParaTxDetails parameter
   421  type ParaTxDetails struct {
   422  	Items []*ParaTxDetail `json:"paraTxDetail"`
   423  }
   424  
   425  //ParaTxDetail parameter
   426  type ParaTxDetail struct {
   427  	Type      int64       `json:"type,omitempty"`
   428  	Header    *Header     `json:"header,omitempty"`
   429  	TxDetails []*TxDetail `json:"txDetail,omitempty"`
   430  	ChildHash string      `json:"childHash,omitempty"`
   431  	Index     uint32      `json:"index,omitempty"`
   432  	Proofs    []string    `json:"proofs,omitempty"`
   433  }
   434  
   435  //TxDetail parameter
   436  type TxDetail struct {
   437  	Index   uint32       `json:"index,omitempty"`
   438  	Tx      *Transaction `json:"tx,omitempty"`
   439  	Receipt *ReceiptData `json:"receipt,omitempty"`
   440  	Proofs  []string     `json:"proofs,omitempty"`
   441  }
   442  
   443  //ReplyHeightByTitle parameter
   444  type ReplyHeightByTitle struct {
   445  	Title string       `json:"title,omitempty"`
   446  	Items []*BlockInfo `json:"items,omitempty"`
   447  }
   448  
   449  //BlockInfo parameter
   450  type BlockInfo struct {
   451  	Height int64  `json:"height,omitempty"`
   452  	Hash   string `json:"hash,omitempty"`
   453  }