Skip to content

Commit

Permalink
Merge branch 'sprint-1.18' into fix/refactor-zboxcore
Browse files Browse the repository at this point in the history
# Conflicts:
#	mobilesdk/zcn/smartcontract.go
#	zboxcore/sdk/transaction_mobile.go
#	zcncore/transaction.go
#	zcncore/transaction_base.go
#	zcncore/transaction_mobile.go
#	zcncore/transactionauth.go
#	zcncore/transactionauth_base.go
#	zcncore/transactionauth_mobile.go
#	zcncore/zauth.go
  • Loading branch information
Jayashsatolia403 committed Sep 27, 2024
2 parents 0277b7b + 4ba58f5 commit f945a84
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 35 deletions.
20 changes: 0 additions & 20 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions core/transaction/transaction.go
Original file line number Diff line number Diff line change
@@ -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"`
}
82 changes: 82 additions & 0 deletions core/transaction/transaction_mobile.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 6 additions & 5 deletions wasmsdk/auth_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 47 in wasmsdk/auth_txn.go

View workflow job for this annotation

GitHub Actions / wasm-test

too many arguments in call to zcncore.CallZvaultNewWalletString

Check failure on line 47 in wasmsdk/auth_txn.go

View workflow job for this annotation

GitHub Actions / Build-wasm

too many arguments in call to zcncore.CallZvaultNewWalletString
}

// 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)

Check failure on line 52 in wasmsdk/auth_txn.go

View workflow job for this annotation

GitHub Actions / wasm-test

too many arguments in call to zcncore.CallZvaultNewWalletString

Check failure on line 52 in wasmsdk/auth_txn.go

View workflow job for this annotation

GitHub Actions / Build-wasm

too many arguments in call to zcncore.CallZvaultNewWalletString
}

func zvaultStoreKey(serverAddr, token, privateKey string) (string, error) {
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 2 additions & 10 deletions wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f945a84

Please sign in to comment.