diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 5c5372dc0..9b4a22ed3 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -37,26 +37,6 @@ const ( TxnFail = 3 // Indicates a transaction has failed to update the state or smart contract ) -// Transaction entity that encapsulates the transaction related data and meta data -type Transaction struct { - Hash string `json:"hash,omitempty"` - Version string `json:"version,omitempty"` - ClientID string `json:"client_id,omitempty"` - PublicKey string `json:"public_key,omitempty"` - ToClientID string `json:"to_client_id,omitempty"` - ChainID string `json:"chain_id,omitempty"` - TransactionData string `json:"transaction_data"` - Value uint64 `json:"transaction_value"` - Signature string `json:"signature,omitempty"` - CreationDate int64 `json:"creation_date,omitempty"` - TransactionType int `json:"transaction_type"` - TransactionOutput string `json:"transaction_output,omitempty"` - TransactionFee uint64 `json:"transaction_fee"` - TransactionNonce int64 `json:"transaction_nonce"` - OutputHash string `json:"txn_output_hash"` - Status int `json:"transaction_status"` -} - // TxnReceipt - a transaction receipt is a processed transaction that contains the output type TxnReceipt struct { Transaction *Transaction diff --git a/core/transaction/transaction.go b/core/transaction/transaction.go new file mode 100644 index 000000000..2040630cf --- /dev/null +++ b/core/transaction/transaction.go @@ -0,0 +1,24 @@ +//go:build !mobile +// +build !mobile + +package transaction + +// Transaction entity that encapsulates the transaction related data and meta data +type Transaction struct { + Hash string `json:"hash,omitempty"` + Version string `json:"version,omitempty"` + ClientID string `json:"client_id,omitempty"` + PublicKey string `json:"public_key,omitempty"` + ToClientID string `json:"to_client_id,omitempty"` + ChainID string `json:"chain_id,omitempty"` + TransactionData string `json:"transaction_data"` + Value uint64 `json:"transaction_value"` + Signature string `json:"signature,omitempty"` + CreationDate int64 `json:"creation_date,omitempty"` + TransactionType int `json:"transaction_type"` + TransactionOutput string `json:"transaction_output,omitempty"` + TransactionFee uint64 `json:"transaction_fee"` + TransactionNonce int64 `json:"transaction_nonce"` + OutputHash string `json:"txn_output_hash"` + Status int `json:"transaction_status"` +} diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go new file mode 100644 index 000000000..3119429e5 --- /dev/null +++ b/core/transaction/transaction_mobile.go @@ -0,0 +1,82 @@ +//go:build mobile +// +build mobile + +package transaction + +import ( + "encoding/json" + "strconv" +) + +// Transaction represents entity that encapsulates the transaction related data and metadata. +type Transaction struct { + Hash string `json:"hash,omitempty"` + Version string `json:"version,omitempty"` + ClientID string `json:"client_id,omitempty"` + PublicKey string `json:"public_key,omitempty"` + ToClientID string `json:"to_client_id,omitempty"` + ChainID string `json:"chain_id,omitempty"` + TransactionData string `json:"transaction_data"` + Value string `json:"transaction_value"` + Signature string `json:"signature,omitempty"` + CreationDate int64 `json:"creation_date,omitempty"` + TransactionType int `json:"transaction_type"` + TransactionOutput string `json:"transaction_output,omitempty"` + TransactionFee string `json:"transaction_fee"` + TransactionNonce int64 `json:"transaction_nonce"` + OutputHash string `json:"txn_output_hash"` + Status int `json:"transaction_status"` +} + +// TransactionWrapper represents wrapper for mobile transaction entity. +type TransactionWrapper struct { + Hash string `json:"hash,omitempty"` + Version string `json:"version,omitempty"` + ClientID string `json:"client_id,omitempty"` + PublicKey string `json:"public_key,omitempty"` + ToClientID string `json:"to_client_id,omitempty"` + ChainID string `json:"chain_id,omitempty"` + TransactionData string `json:"transaction_data"` + Value uint64 `json:"transaction_value"` + Signature string `json:"signature,omitempty"` + CreationDate int64 `json:"creation_date,omitempty"` + TransactionType int `json:"transaction_type"` + TransactionOutput string `json:"transaction_output,omitempty"` + TransactionFee uint64 `json:"transaction_fee"` + TransactionNonce int64 `json:"transaction_nonce"` + OutputHash string `json:"txn_output_hash"` + Status int `json:"transaction_status"` +} + +func (t *Transaction) MarshalJSON() ([]byte, error) { + valueRaw, err := strconv.ParseUint(t.Value, 0, 64) + if err != nil { + return nil, err + } + + transactionFeeRaw, err := strconv.ParseUint(t.TransactionFee, 0, 64) + if err != nil { + return nil, err + } + + wrapper := TransactionWrapper{ + Hash: t.Hash, + Version: t.Version, + ClientID: t.ClientID, + PublicKey: t.PublicKey, + ToClientID: t.ToClientID, + ChainID: t.ChainID, + TransactionData: t.TransactionData, + Value: valueRaw, + Signature: t.Signature, + CreationDate: t.CreationDate, + TransactionType: t.TransactionType, + TransactionOutput: t.TransactionOutput, + TransactionFee: transactionFeeRaw, + TransactionNonce: t.TransactionNonce, + OutputHash: t.OutputHash, + Status: t.Status, + } + + return json.Marshal(wrapper) +} diff --git a/wasmsdk/auth_txn.go b/wasmsdk/auth_txn.go index 5e2357787..e9c8d71c0 100644 --- a/wasmsdk/auth_txn.go +++ b/wasmsdk/auth_txn.go @@ -43,13 +43,13 @@ func registerZauthServer(serverAddr string) { } // zvaultNewWallet generates new split wallet -func zvaultNewWallet(serverAddr, token string) (string, error) { - return zcncore.CallZvaultNewWalletString(serverAddr, token, "") +func zvaultNewWallet(serverAddr, token string, roles []string) (string, error) { + return zcncore.CallZvaultNewWalletString(serverAddr, token, "", nil) } // zvaultNewSplit generates new split wallet from existing clientID -func zvaultNewSplit(clientID, serverAddr, token string) (string, error) { - return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID) +func zvaultNewSplit(clientID, serverAddr, token string, roles []string) (string, error) { + return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID, roles) } func zvaultStoreKey(serverAddr, token, privateKey string) (string, error) { @@ -92,7 +92,8 @@ func registerAuthCommon(this js.Value, args []js.Value) interface{} { } // authResponse Publishes the response to the authorization request. -// `response` is the response to the authorization request. +// +// `response` is the response to the authorization request. func authResponse(response string) { authResponseC <- response } diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index f7dd1c4ac..9157c52a9 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -81,11 +81,7 @@ func main() { return "", fmt.Errorf("failed to sign with split key: %v", err) } - data, err := json.Marshal(struct { - Hash string `json:"hash"` - Signature string `json:"signature"` - ClientID string `json:"client_id"` - }{ + data, err := json.Marshal(zcncore.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID, @@ -369,11 +365,7 @@ func main() { return "", fmt.Errorf("failed to sign with split key: %v", err) } - data, err := json.Marshal(struct { - Hash string `json:"hash"` - Signature string `json:"signature"` - ClientID string `json:"client_id"` - }{ + data, err := json.Marshal(zcncore.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID,