github.com/0chain/gosdk@v1.17.11/core/transaction/transaction_mobile.go (about) 1 //go:build mobile 2 // +build mobile 3 4 package transaction 5 6 import ( 7 "encoding/json" 8 "strconv" 9 ) 10 11 // Transaction represents entity that encapsulates the transaction related data and metadata. 12 type Transaction struct { 13 Hash string `json:"hash,omitempty"` 14 Version string `json:"version,omitempty"` 15 ClientID string `json:"client_id,omitempty"` 16 PublicKey string `json:"public_key,omitempty"` 17 ToClientID string `json:"to_client_id,omitempty"` 18 ChainID string `json:"chain_id,omitempty"` 19 TransactionData string `json:"transaction_data"` 20 Value string `json:"transaction_value"` 21 Signature string `json:"signature,omitempty"` 22 CreationDate int64 `json:"creation_date,omitempty"` 23 TransactionType int `json:"transaction_type"` 24 TransactionOutput string `json:"transaction_output,omitempty"` 25 TransactionFee string `json:"transaction_fee"` 26 TransactionNonce int64 `json:"transaction_nonce"` 27 OutputHash string `json:"txn_output_hash"` 28 Status int `json:"transaction_status"` 29 } 30 31 // TransactionWrapper represents wrapper for mobile transaction entity. 32 type TransactionWrapper struct { 33 Hash string `json:"hash,omitempty"` 34 Version string `json:"version,omitempty"` 35 ClientID string `json:"client_id,omitempty"` 36 PublicKey string `json:"public_key,omitempty"` 37 ToClientID string `json:"to_client_id,omitempty"` 38 ChainID string `json:"chain_id,omitempty"` 39 TransactionData string `json:"transaction_data"` 40 Value uint64 `json:"transaction_value"` 41 Signature string `json:"signature,omitempty"` 42 CreationDate int64 `json:"creation_date,omitempty"` 43 TransactionType int `json:"transaction_type"` 44 TransactionOutput string `json:"transaction_output,omitempty"` 45 TransactionFee uint64 `json:"transaction_fee"` 46 TransactionNonce int64 `json:"transaction_nonce"` 47 OutputHash string `json:"txn_output_hash"` 48 Status int `json:"transaction_status"` 49 } 50 51 func (t *Transaction) MarshalJSON() ([]byte, error) { 52 valueRaw, err := strconv.ParseUint(t.Value, 0, 64) 53 if err != nil { 54 return nil, err 55 } 56 57 transactionFeeRaw, err := strconv.ParseUint(t.TransactionFee, 0, 64) 58 if err != nil { 59 return nil, err 60 } 61 62 wrapper := TransactionWrapper{ 63 Hash: t.Hash, 64 Version: t.Version, 65 ClientID: t.ClientID, 66 PublicKey: t.PublicKey, 67 ToClientID: t.ToClientID, 68 ChainID: t.ChainID, 69 TransactionData: t.TransactionData, 70 Value: valueRaw, 71 Signature: t.Signature, 72 CreationDate: t.CreationDate, 73 TransactionType: t.TransactionType, 74 TransactionOutput: t.TransactionOutput, 75 TransactionFee: transactionFeeRaw, 76 TransactionNonce: t.TransactionNonce, 77 OutputHash: t.OutputHash, 78 Status: t.Status, 79 } 80 81 return json.Marshal(wrapper) 82 }