From e93ee658d27dad14652e90c4ebe5e3cd3c528918 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 17 Sep 2024 02:15:54 +0200 Subject: [PATCH 01/43] feature: provided required changes for other kms components --- wasmsdk/proxy.go | 12 ++--------- zcncore/zauth.go | 52 ++++++++---------------------------------------- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index 1253c106c..0ba39b483 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -82,11 +82,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(zauth.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID, @@ -384,11 +380,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(zauth.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID, diff --git a/zcncore/zauth.go b/zcncore/zauth.go index 0ab96d5c0..eacd470f3 100644 --- a/zcncore/zauth.go +++ b/zcncore/zauth.go @@ -15,13 +15,14 @@ import ( // SplitWallet represents wallet info for split wallet // The client id and client key are the same as the primary wallet client id and client key type SplitWallet struct { - ClientID string `json:"client_id"` - ClientKey string `json:"client_key"` - PublicKey string `json:"public_key"` - PrivateKey string `json:"private_key"` - PeerPublicKey string `json:"peer_public_key"` - IsRevoked bool `json:"is_revoked"` - ExpiredAt int64 `json:"expired_at"` + ClientID string `json:"client_id"` + ClientKey string `json:"client_key"` + PublicKey string `json:"public_key"` + PrivateKey string `json:"private_key"` + PeerPublicKey string `json:"peer_public_key"` + Roles []string `json:"roles"` + IsRevoked bool `json:"is_revoked"` + ExpiredAt int64 `json:"expired_at"` } // CallZauthSetup calls the zauth setup endpoint @@ -452,7 +453,6 @@ func ZauthSignTxn(serverAddr string) sys.AuthorizeFunc { func ZauthAuthCommon(serverAddr string) sys.AuthorizeFunc { return func(msg string) (string, error) { - // return func(msg string) (string, error) { req, err := http.NewRequest("POST", serverAddr+"/sign/msg", bytes.NewBuffer([]byte(msg))) if err != nil { return "", errors.Wrap(err, "failed to create HTTP request") @@ -496,39 +496,3 @@ type AuthMessage struct { type AuthResponse struct { Sig string `json:"sig"` } - -func ZauthSignMsg(serverAddr string) sys.SignFunc { - return func(hash string, signatureScheme string, keys []sys.KeyPair) (string, error) { - sig, err := SignWithKey(keys[0].PrivateKey, hash) - if err != nil { - return "", err - } - - data, err := json.Marshal(AuthMessage{ - Hash: hash, - Signature: sig, - ClientID: client.GetClient().ClientID, - }) - if err != nil { - return "", err - } - - // fmt.Println("auth - sys.AuthCommon:", sys.AuthCommon) - if sys.AuthCommon == nil { - return "", errors.New("authCommon is not set") - } - - rsp, err := sys.AuthCommon(string(data)) - if err != nil { - return "", err - } - - var ar AuthResponse - err = json.Unmarshal([]byte(rsp), &ar) - if err != nil { - return "", err - } - - return AddSignature(client.GetClientPrivateKey(), ar.Sig, hash) - } -} From 09a82f19311aa3b8eb2bb26a1ef2e50e8b50bbe0 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 17 Sep 2024 15:56:29 +0200 Subject: [PATCH 02/43] fix: fixed bugs --- wasmsdk/auth_txn.go | 5 +++-- zcncore/zauth.go | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/wasmsdk/auth_txn.go b/wasmsdk/auth_txn.go index 5e2357787..184b52018 100644 --- a/wasmsdk/auth_txn.go +++ b/wasmsdk/auth_txn.go @@ -48,7 +48,7 @@ func zvaultNewWallet(serverAddr, token string) (string, error) { } // zvaultNewSplit generates new split wallet from existing clientID -func zvaultNewSplit(clientID, serverAddr, token string) (string, error) { +func zvaultNewSplit(clientID, serverAddr, token string, roles []string) (string, error) { return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID) } @@ -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/zcncore/zauth.go b/zcncore/zauth.go index eacd470f3..b10cd7bc7 100644 --- a/zcncore/zauth.go +++ b/zcncore/zauth.go @@ -153,14 +153,25 @@ func CallZauthDelete(serverAddr, token, clientID string) error { return nil } -func CallZvaultNewWalletString(serverAddr, token, clientID string) (string, error) { +type newWalletRequest struct { + Roles []string `json:"roles"` +} + +func CallZvaultNewWalletString(serverAddr, token, clientID string, roles []string) (string, error) { // Add your code here endpoint := serverAddr + "/generate" if clientID != "" { endpoint = endpoint + "/" + clientID } - req, err := http.NewRequest("POST", endpoint, nil) + data, err := json.Marshal(newWalletRequest{ + Roles: roles, + }) + if err != nil { + return "", errors.Wrap(err, "failed to serialize request") + } + + req, err := http.NewRequest("POST", endpoint, bytes.NewReader(data)) if err != nil { return "", errors.Wrap(err, "failed to create HTTP request") } From 63de8fd7af203ae2002298b1820efdf2d20dfc83 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:11:46 +0200 Subject: [PATCH 03/43] fix: mobed transaction scheme to mobile package --- zcncore/transaction_mobile.go | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 597ead572..903c3dcbe 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -92,6 +92,46 @@ type TransactionCommon interface { GetVerifyConfirmationStatus() int } +type TransactionScheme interface { + TransactionCommon + // SetTransactionCallback implements storing the callback + // used to call after the transaction or verification is completed + SetTransactionCallback(cb TransactionCallback) error + // StoreData implements store the data to blockchain + StoreData(data string) error + // ExecuteFaucetSCWallet implements the `Faucet Smart contract` for a given wallet + ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error + // GetTransactionHash implements retrieval of hash of the submitted transaction + GetTransactionHash() string + // SetTransactionHash implements verify a previous transaction status + SetTransactionHash(hash string) error + // SetTransactionNonce implements method to set the transaction nonce + SetTransactionNonce(txnNonce int64) error + // Verify implements verify the transaction + Verify() error + // GetVerifyOutput implements the verification output from sharders + GetVerifyOutput() string + // GetTransactionError implements error string in case of transaction failure + GetTransactionError() string + // GetVerifyError implements error string in case of verify failure error + GetVerifyError() string + // GetTransactionNonce returns nonce + GetTransactionNonce() int64 + + // Output of transaction. + Output() []byte + + // Hash Transaction status regardless of status + Hash() string + + // Vesting SC + + VestingTrigger(poolID string) error + VestingStop(sr *VestingStopRequest) error + VestingUnlock(poolID string) error + VestingDelete(poolID string) error +} + // priceRange represents a price range allowed by user to filter blobbers. type priceRange struct { Min int64 `json:"min"` From 7022069088246cf0c4737e924704c51b82f63a81 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:22:26 +0200 Subject: [PATCH 04/43] fix: fixed bugs --- zcncore/transaction.go | 51 +++++++++++++++++++++++++++++++++++ zcncore/transaction_base.go | 51 ----------------------------------- zcncore/transaction_mobile.go | 11 ++++++++ 3 files changed, 62 insertions(+), 51 deletions(-) diff --git a/zcncore/transaction.go b/zcncore/transaction.go index 17eb01b1e..dbd0b3886 100644 --- a/zcncore/transaction.go +++ b/zcncore/transaction.go @@ -178,6 +178,57 @@ type TransactionCommon interface { ZCNSCCollectReward(providerID string, providerType Provider) error } +// compiler time check +var ( + _ TransactionScheme = (*Transaction)(nil) + _ TransactionScheme = (*TransactionWithAuth)(nil) +) + +// TransactionScheme implements few methods for block chain. +// +// Note: to be buildable on MacOSX all arguments should have names. +type TransactionScheme interface { + TransactionCommon + // SetTransactionCallback implements storing the callback + // used to call after the transaction or verification is completed + SetTransactionCallback(cb TransactionCallback) error + // StoreData implements store the data to blockchain + StoreData(data string) error + // ExecuteFaucetSCWallet implements the `Faucet Smart contract` for a given wallet + ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error + // GetTransactionHash implements retrieval of hash of the submitted transaction + GetTransactionHash() string + // SetTransactionHash implements verify a previous transaction status + SetTransactionHash(hash string) error + // SetTransactionNonce implements method to set the transaction nonce + SetTransactionNonce(txnNonce int64) error + // Verify implements verify the transaction + Verify() error + // GetVerifyOutput implements the verification output from sharders + GetVerifyOutput() string + // GetTransactionError implements error string in case of transaction failure + GetTransactionError() string + // GetVerifyError implements error string in case of verify failure error + GetVerifyError() string + // GetTransactionNonce returns nonce + GetTransactionNonce() int64 + + // Output of transaction. + Output() []byte + + // Hash Transaction status regardless of status + Hash() string + + // Vesting SC + + VestingTrigger(poolID string) error + VestingStop(sr *VestingStopRequest) error + VestingUnlock(poolID string) error + VestingDelete(poolID string) error + + // Miner SC +} + // PriceRange represents a price range allowed by user to filter blobbers. type PriceRange struct { Min common.Balance `json:"min"` diff --git a/zcncore/transaction_base.go b/zcncore/transaction_base.go index 8d3ca6420..2cb8e8706 100644 --- a/zcncore/transaction_base.go +++ b/zcncore/transaction_base.go @@ -26,12 +26,6 @@ import ( "github.com/0chain/gosdk/zboxcore/blockchain" ) -// compiler time check -var ( - _ TransactionScheme = (*Transaction)(nil) - _ TransactionScheme = (*TransactionWithAuth)(nil) -) - var ( errNetwork = errors.New("", "network error. host not reachable") errUserRejected = errors.New("", "rejected by user") @@ -40,51 +34,6 @@ var ( errAddSignature = errors.New("", "error adding signature") ) -// TransactionScheme implements few methods for block chain. -// -// Note: to be buildable on MacOSX all arguments should have names. -type TransactionScheme interface { - TransactionCommon - // SetTransactionCallback implements storing the callback - // used to call after the transaction or verification is completed - SetTransactionCallback(cb TransactionCallback) error - // StoreData implements store the data to blockchain - StoreData(data string) error - // ExecuteFaucetSCWallet implements the `Faucet Smart contract` for a given wallet - ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error - // GetTransactionHash implements retrieval of hash of the submitted transaction - GetTransactionHash() string - // SetTransactionHash implements verify a previous transaction status - SetTransactionHash(hash string) error - // SetTransactionNonce implements method to set the transaction nonce - SetTransactionNonce(txnNonce int64) error - // Verify implements verify the transaction - Verify() error - // GetVerifyOutput implements the verification output from sharders - GetVerifyOutput() string - // GetTransactionError implements error string in case of transaction failure - GetTransactionError() string - // GetVerifyError implements error string in case of verify failure error - GetVerifyError() string - // GetTransactionNonce returns nonce - GetTransactionNonce() int64 - - // Output of transaction. - Output() []byte - - // Hash Transaction status regardless of status - Hash() string - - // Vesting SC - - VestingTrigger(poolID string) error - VestingStop(sr *VestingStopRequest) error - VestingUnlock(poolID string) error - VestingDelete(poolID string) error - - // Miner SC -} - // TransactionCallback needs to be implemented by the caller for transaction related APIs type TransactionCallback interface { OnTransactionComplete(t *Transaction, status int) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 903c3dcbe..3e5876fe3 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -45,6 +45,12 @@ type stakePoolRequest struct { ProviderID string `json:"provider_id,omitempty"` } +// compiler time check +var ( + _ TransactionScheme = (*Transaction)(nil) + _ TransactionScheme = (*TransactionWithAuth)(nil) +) + type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function ExecuteSmartContract(address, methodName string, input interface{}, val uint64, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -92,6 +98,9 @@ type TransactionCommon interface { GetVerifyConfirmationStatus() int } +// TransactionScheme implements few methods for block chain. +// +// Note: to be buildable on MacOSX all arguments should have names. type TransactionScheme interface { TransactionCommon // SetTransactionCallback implements storing the callback @@ -130,6 +139,8 @@ type TransactionScheme interface { VestingStop(sr *VestingStopRequest) error VestingUnlock(poolID string) error VestingDelete(poolID string) error + + // Miner SC } // priceRange represents a price range allowed by user to filter blobbers. From 33e10f4d2f9b51e57b1d3c102725354ae89a1adf Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:38:12 +0200 Subject: [PATCH 05/43] fix: debug --- zcncore/transaction_mobile.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 9fd5f8f86..8c4f8a1b2 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,6 +53,8 @@ var ( type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function + ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction + ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) // Send implements sending token to a given clientid @@ -67,7 +69,7 @@ type TransactionCommon interface { FinalizeAllocation(allocID string) error CancelAllocation(allocID string) error - CreateAllocation(car *CreateAllocationRequest, lock string) error // + CreateAllocation(car *CreateAllocationRequest, lock string) error CreateReadPool() error ReadPoolLock(allocID string, blobberID string, duration int64, lock string) error ReadPoolUnlock() error @@ -415,6 +417,11 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac return t, err } +// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain +func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction { + return nil +} + // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { v, err := parseCoinStr(val) From dcd90b470e92f4484dcd71e12709a59a1d2cd7c5 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:40:03 +0200 Subject: [PATCH 06/43] fix: debug --- zcncore/transactionauth_mobile.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 03af33415..f90d188b9 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -11,6 +11,11 @@ import ( "github.com/0chain/gosdk/core/transaction" ) +// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction { + return nil +} + func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { v, err := parseCoinStr(val) From 79afc501f39e14d2d0df018f9c8b72ea641b5c2f Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:46:59 +0200 Subject: [PATCH 07/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 8c4f8a1b2..3bf9a87fe 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function - ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction + ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -418,7 +418,7 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { return nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index f90d188b9..c25b5fb33 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -12,7 +12,7 @@ import ( ) // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) *transaction.Transaction { +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { return nil } From f4cdc7bdfbf8e51fcde1789ba2c5e65719aee2ee Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:48:12 +0200 Subject: [PATCH 08/43] fix: debug --- zcncore/transaction_mobile.go | 2 +- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 3bf9a87fe..dd0637964 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -419,7 +419,7 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { - return nil + return nil, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index c25b5fb33..4c00612d5 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -13,7 +13,7 @@ import ( // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { - return nil + return nil, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 59cfb3db84588e13dfa4d87c1b3a50e8f0ba44fe Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 15:56:05 +0200 Subject: [PATCH 09/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index dd0637964..79991958f 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function - ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) + ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -418,7 +418,7 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { +func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) { return nil, nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 4c00612d5..753c44a28 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -12,7 +12,7 @@ import ( ) // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) { return nil, nil } From 9832c2908f4ad6df7fd1f2badf2770ac116cf7cf Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 16:08:28 +0200 Subject: [PATCH 10/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 79991958f..ef3aa27b5 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function - ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) + ExecuteSmartContracts(address, methodName, val string) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -418,8 +418,8 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) { - return nil, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) error { + return nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 753c44a28..cfb6a5e35 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -12,8 +12,8 @@ import ( ) // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) (*transaction.Transaction, error) { - return nil, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) error { + return nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 46ac0945ec761e7587b6e0238374e671322fbe45 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 16:46:55 +0200 Subject: [PATCH 11/43] fix: debug --- zcncore/transaction_mobile.go | 8 ++++---- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index ef3aa27b5..5164dfdb3 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,9 +53,9 @@ var ( type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function - ExecuteSmartContracts(address, methodName, val string) error + ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) - ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) + ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (transaction.Transaction, error) // Send implements sending token to a given clientid Send(toClientID string, val string, desc string) error @@ -418,8 +418,8 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) error { - return nil +func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index cfb6a5e35..d2a035928 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -12,8 +12,8 @@ import ( ) // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) error { - return nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 6345dc586a318e0433dab5d1546134ab1a29fa49 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 16:49:43 +0200 Subject: [PATCH 12/43] fix: debug --- zcncore/transaction_mobile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 5164dfdb3..1a050cf3b 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -55,7 +55,7 @@ type TransactionCommon interface { // ExecuteSmartContract implements wrapper for smart contract function ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) - ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (transaction.Transaction, error) + ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) // Send implements sending token to a given clientid Send(toClientID string, val string, desc string) error From 5b066158e126984f8b87e6a80629b985c6dc8572 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 23 Sep 2024 17:09:36 +0200 Subject: [PATCH 13/43] fix: debug --- core/transaction/entity.go | 20 -------------------- core/transaction/transaction.go | 24 ++++++++++++++++++++++++ core/transaction/transaction_mobile.go | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 core/transaction/transaction.go create mode 100644 core/transaction/transaction_mobile.go diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 4c6656e86..2f9ea82ab 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -26,26 +26,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..4808dead9 --- /dev/null +++ b/core/transaction/transaction_mobile.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 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"` +} From edbda45ea35bb74dd086decde23919dbd31014c3 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 00:51:42 +0200 Subject: [PATCH 14/43] fix: fixed bugs --- core/transaction/transaction_mobile.go | 60 ++++++++++++++++++- zcncore/transaction.go | 10 ++++ zcncore/transaction_base.go | 10 ---- zcncore/transaction_mobile.go | 82 +++++++------------------- zcncore/transactionauth.go | 7 +++ zcncore/transactionauth_base.go | 7 --- zcncore/transactionauth_mobile.go | 15 ++--- 7 files changed, 103 insertions(+), 88 deletions(-) diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 4808dead9..3119429e5 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -3,7 +3,12 @@ package transaction -// Transaction entity that encapsulates the transaction related data and meta data +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"` @@ -22,3 +27,56 @@ type Transaction struct { 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/zcncore/transaction.go b/zcncore/transaction.go index dbd0b3886..0153066cc 100644 --- a/zcncore/transaction.go +++ b/zcncore/transaction.go @@ -323,6 +323,16 @@ type InputMap struct { Fields map[string]string `json:"Fields"` } +func newTransaction(cb TransactionCallback, txnFee uint64, nonce int64) (*Transaction, error) { + t := &Transaction{} + t.txn = transaction.NewTransactionEntity(_config.wallet.ClientID, _config.chain.ChainID, _config.wallet.ClientKey, nonce) + t.txnStatus, t.verifyStatus = StatusUnknown, StatusUnknown + t.txnCb = cb + t.txn.TransactionNonce = nonce + t.txn.TransactionFee = txnFee + return t, nil +} + // NewTransaction new generic transaction object for any operation // - cb: callback for transaction state // - txnFee: Transaction fees (in SAS tokens) diff --git a/zcncore/transaction_base.go b/zcncore/transaction_base.go index 2cb8e8706..89407d720 100644 --- a/zcncore/transaction_base.go +++ b/zcncore/transaction_base.go @@ -397,16 +397,6 @@ func (t *Transaction) submitTxn() { } } -func newTransaction(cb TransactionCallback, txnFee uint64, nonce int64) (*Transaction, error) { - t := &Transaction{} - t.txn = transaction.NewTransactionEntity(_config.wallet.ClientID, _config.chain.ChainID, _config.wallet.ClientKey, nonce) - t.txnStatus, t.verifyStatus = StatusUnknown, StatusUnknown - t.txnCb = cb - t.txn.TransactionNonce = nonce - t.txn.TransactionFee = txnFee - return t, nil -} - // SetTransactionCallback implements storing the callback func (t *Transaction) SetTransactionCallback(cb TransactionCallback) error { if t.txnStatus != StatusUnknown { diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 1a050cf3b..1077a37a2 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -52,9 +52,6 @@ var ( ) type TransactionCommon interface { - // ExecuteSmartContract implements wrapper for smart contract function - ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) - ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) // Send implements sending token to a given clientid @@ -390,16 +387,21 @@ func parseCoinStr(vs string) (uint64, error) { return v, nil } +func newTransaction(cb TransactionCallback, txnFee string, nonce int64) (*Transaction, error) { + t := &Transaction{} + t.txn = transaction.NewTransactionEntity(_config.wallet.ClientID, _config.chain.ChainID, _config.wallet.ClientKey, nonce) + t.txnStatus, t.verifyStatus = StatusUnknown, StatusUnknown + t.txnCb = cb + t.txn.TransactionNonce = nonce + t.txn.TransactionFee = txnFee + return t, nil +} + // NewTransaction new generic transaction object for any operation // - cb: callback for transaction state // - txnFee: Transaction fees (in SAS tokens) // - nonce: latest nonce of current wallet. please set it with 0 if you don't know the latest value func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (TransactionScheme, error) { - txnFeeRaw, err := parseCoinStr(txnFee) - if err != nil { - return nil, err - } - err = CheckConfig() if err != nil { return nil, err @@ -412,16 +414,12 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac logging.Info("New transaction interface with auth") return newTransactionWithAuth(cb, txnFeeRaw, nonce) } + logging.Info("New transaction interface") - t, err := newTransaction(cb, txnFeeRaw, nonce) + t, err := newTransaction(cb, txnFee, nonce) return t, err } -// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil -} - // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { v, err := parseCoinStr(val) @@ -440,21 +438,8 @@ func (t *Transaction) ExecuteSmartContract(address, methodName string, input int return t.txn, nil } -func (t *Transaction) setTransactionFee(fee uint64) error { - if t.txnStatus != StatusUnknown { - return errors.New("", "transaction already exists. cannot set transaction fee.") - } - t.txn.TransactionFee = fee - return nil -} - // Send to send a transaction to a given clientID func (t *Transaction) Send(toClientID string, val string, desc string) error { - v, err := parseCoinStr(val) - if err != nil { - return nil - } - txnData, err := json.Marshal(SendTxnData{Note: desc}) if err != nil { return errors.New("", "Could not serialize description to transaction_data") @@ -462,7 +447,7 @@ func (t *Transaction) Send(toClientID string, val string, desc string) error { go func() { t.txn.TransactionType = transaction.TxnTypeSend t.txn.ToClientID = toClientID - t.txn.Value = v + t.txn.Value = val t.txn.TransactionData = string(txnData) t.setNonceAndSubmit() }() @@ -477,11 +462,6 @@ func (t *Transaction) Send(toClientID string, val string, desc string) error { // - CreationDate: creation date of the transaction // - hash: hash of the transaction func (t *Transaction) SendWithSignatureHash(toClientID string, val string, desc string, sig string, CreationDate int64, hash string) error { - v, err := parseCoinStr(val) - if err != nil { - return err - } - txnData, err := json.Marshal(SendTxnData{Note: desc}) if err != nil { return errors.New("", "Could not serialize description to transaction_data") @@ -489,7 +469,7 @@ func (t *Transaction) SendWithSignatureHash(toClientID string, val string, desc go func() { t.txn.TransactionType = transaction.TxnTypeSend t.txn.ToClientID = toClientID - t.txn.Value = v + t.txn.Value = val t.txn.Hash = hash t.txn.TransactionData = string(txnData) t.txn.Signature = sig @@ -1383,25 +1363,25 @@ type Block struct { ClientStateHash string `json:"state_hash"` // unexported fields - header *BlockHeader `json:"-"` - txns []*TransactionMobile `json:"transactions,omitempty"` + header *BlockHeader `json:"-"` + txns []*transaction.Transaction `json:"transactions,omitempty"` } func (b *Block) GetHeader() *BlockHeader { return b.header } -type IterTxnFunc func(idx int, txn *TransactionMobile) +type IterTxnFunc func(idx int, txn *transaction.Transaction) type Transactions struct { - txns []*TransactionMobile + txns []*transaction.Transaction } func (tm *Transactions) Len() int { return len(tm.txns) } -func (tm *Transactions) Get(idx int) (*TransactionMobile, error) { +func (tm *Transactions) Get(idx int) (*transaction.Transaction, error) { if idx < 0 && idx >= len(tm.txns) { return nil, stderrors.New("index out of bounds") } @@ -1449,9 +1429,9 @@ func toMobileBlock(b *block.Block) *Block { ClientStateHash: string(b.ClientStateHash), } - lb.txns = make([]*TransactionMobile, len(b.Txns)) + lb.txns = make([]*transaction.Transaction, len(b.Txns)) for i, txn := range b.Txns { - lb.txns[i] = &TransactionMobile{ + lb.txns[i] = &transaction.Transaction{ Hash: txn.Hash, Version: txn.Version, ClientID: txn.ClientID, @@ -1474,26 +1454,6 @@ func toMobileBlock(b *block.Block) *Block { return lb } -// TransactionMobile entity that encapsulates the transaction related data and meta data -type TransactionMobile 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"` -} - // RequestTimeout will be used for setting requests with timeout type RequestTimeout interface { Set(int64) // milliseconds diff --git a/zcncore/transactionauth.go b/zcncore/transactionauth.go index c67906742..824cab27e 100644 --- a/zcncore/transactionauth.go +++ b/zcncore/transactionauth.go @@ -13,6 +13,13 @@ import ( "github.com/0chain/gosdk/core/transaction" ) +func newTransactionWithAuth(cb TransactionCallback, txnFee uint64, nonce int64) (*TransactionWithAuth, error) { + ta := &TransactionWithAuth{} + var err error + ta.t, err = newTransaction(cb, txnFee, nonce) + return ta, err +} + func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, input interface{}, val uint64, feeOpts ...FeeOption) (*transaction.Transaction, error) { err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) diff --git a/zcncore/transactionauth_base.go b/zcncore/transactionauth_base.go index 0abdb4f49..7f8b8848c 100644 --- a/zcncore/transactionauth_base.go +++ b/zcncore/transactionauth_base.go @@ -23,13 +23,6 @@ func (ta *TransactionWithAuth) SetTransactionNonce(txnNonce int64) error { return ta.t.SetTransactionNonce(txnNonce) } -func newTransactionWithAuth(cb TransactionCallback, txnFee uint64, nonce int64) (*TransactionWithAuth, error) { - ta := &TransactionWithAuth{} - var err error - ta.t, err = newTransaction(cb, txnFee, nonce) - return ta, err -} - func (ta *TransactionWithAuth) getAuthorize() (*transaction.Transaction, error) { ta.t.txn.PublicKey = _config.wallet.ClientKey err := ta.t.txn.ComputeHashAndSign(SignFn) diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index d2a035928..4aa31c9cf 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -11,9 +11,11 @@ import ( "github.com/0chain/gosdk/core/transaction" ) -// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName, val string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil +func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) (*TransactionWithAuth, error) { + ta := &TransactionWithAuth{} + var err error + ta.t, err = newTransaction(cb, txnFee, nonce) + return ta, err } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, @@ -34,11 +36,6 @@ func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, } func (ta *TransactionWithAuth) Send(toClientID string, val string, desc string) error { - v, err := parseCoinStr(val) - if err != nil { - return nil - } - txnData, err := json.Marshal(SendTxnData{Note: desc}) if err != nil { return errors.New("", "Could not serialize description to transaction_data") @@ -46,7 +43,7 @@ func (ta *TransactionWithAuth) Send(toClientID string, val string, desc string) go func() { ta.t.txn.TransactionType = transaction.TxnTypeSend ta.t.txn.ToClientID = toClientID - ta.t.txn.Value = v + ta.t.txn.Value = val ta.t.txn.TransactionData = string(txnData) ta.submitTxn() }() From cef99f3db1f6d74415c01932c9c624f1bada39ab Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 01:55:09 +0200 Subject: [PATCH 15/43] fix: fixed bugs --- zcncore/transaction.go | 99 ++++++++++++ zcncore/transaction_base.go | 106 ------------- zcncore/transaction_mobile.go | 251 ++++++++++++++++++------------ zcncore/transactionauth_mobile.go | 111 +++++-------- 4 files changed, 283 insertions(+), 284 deletions(-) diff --git a/zcncore/transaction.go b/zcncore/transaction.go index 0153066cc..8a7b01972 100644 --- a/zcncore/transaction.go +++ b/zcncore/transaction.go @@ -19,6 +19,7 @@ import ( "github.com/0chain/gosdk/core/node" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/core/util" + "github.com/0chain/gosdk/core/zcncrypto" ) // Provider represents the type of provider. @@ -351,6 +352,55 @@ func NewTransaction(cb TransactionCallback, txnFee uint64, nonce int64) (Transac return newTransaction(cb, txnFee, nonce) } +func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value uint64, opts ...FeeOption) error { + sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} + snBytes, err := json.Marshal(sn) + if err != nil { + return errors.Wrap(err, "create smart contract failed due to invalid data") + } + + t.txn.TransactionType = transaction.TxnTypeSmartContract + t.txn.ToClientID = address + t.txn.TransactionData = string(snBytes) + t.txn.Value = value + + if t.txn.TransactionFee > 0 { + return nil + } + + tf := &TxnFeeOption{} + for _, opt := range opts { + opt(tf) + } + + if tf.noEstimateFee { + return nil + } + + // TODO: check if transaction is exempt to avoid unnecessary fee estimation + minFee, err := transaction.EstimateFee(t.txn, _config.chain.Miners, 0.2) + if err != nil { + return err + } + + t.txn.TransactionFee = minFee + + return nil +} + +func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, input []byte) (*zcncrypto.Wallet, error) { + w, err := getWallet(walletStr) + if err != nil { + fmt.Printf("Error while parsing the wallet. %v\n", err) + return nil, err + } + err = t.createSmartContractTxn(FaucetSmartContractAddress, methodName, input, 0) + if err != nil { + return nil, err + } + return w, nil +} + func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val uint64, opts ...FeeOption) (*transaction.Transaction, error) { err := t.createSmartContractTxn(address, methodName, input, val, opts...) if err != nil { @@ -437,6 +487,55 @@ func (t *Transaction) VestingAdd(ar *VestingAddRequest, value uint64) ( return } +func (t *Transaction) VestingStop(sr *VestingStopRequest) (err error) { + err = t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_STOP, sr, 0) + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} + +func (t *Transaction) vestingPoolTxn(function string, poolID string, + value uint64) error { + + return t.createSmartContractTxn(VestingSmartContractAddress, + function, vestingRequest{PoolID: common.Key(poolID)}, value) +} + +func (t *Transaction) VestingTrigger(poolID string) (err error) { + + err = t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} + +func (t *Transaction) VestingUnlock(poolID string) (err error) { + err = t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} + +func (t *Transaction) VestingDelete(poolID string) (err error) { + err = t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} + func (t *Transaction) MinerSCLock(providerId string, providerType Provider, lock uint64) error { if lock > math.MaxInt64 { return errors.New("invalid_lock", "int64 overflow on lock value") diff --git a/zcncore/transaction_base.go b/zcncore/transaction_base.go index 89407d720..a863b11c8 100644 --- a/zcncore/transaction_base.go +++ b/zcncore/transaction_base.go @@ -14,8 +14,6 @@ import ( "github.com/0chain/gosdk/core/node" "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/zboxcore/fileref" - "github.com/0chain/gosdk/zboxcore/logger" - "go.uber.org/zap" "github.com/0chain/gosdk/core/conf" "github.com/0chain/gosdk/core/encryption" @@ -442,58 +440,6 @@ func WithNoEstimateFee() FeeOption { } } -func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value uint64, opts ...FeeOption) error { - sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} - snBytes, err := json.Marshal(sn) - if err != nil { - return errors.Wrap(err, "create smart contract failed due to invalid data") - } - - t.txn.TransactionType = transaction.TxnTypeSmartContract - t.txn.ToClientID = address - t.txn.TransactionData = string(snBytes) - t.txn.Value = value - - if t.txn.TransactionFee > 0 { - return nil - } - - tf := &TxnFeeOption{} - for _, opt := range opts { - opt(tf) - } - - if tf.noEstimateFee { - return nil - } - - // TODO: check if transaction is exempt to avoid unnecessary fee estimation - minFee, err := transaction.EstimateFee(t.txn, _config.chain.Miners, 0.2) - if err != nil { - logger.Logger.Error("failed estimate txn fee", - zap.Any("txn", t.txn.Hash), - zap.Error(err)) - return err - } - - t.txn.TransactionFee = minFee - - return nil -} - -func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, input []byte) (*zcncrypto.Wallet, error) { - w, err := getWallet(walletStr) - if err != nil { - fmt.Printf("Error while parsing the wallet. %v\n", err) - return nil, err - } - err = t.createSmartContractTxn(FaucetSmartContractAddress, methodName, input, 0) - if err != nil { - return nil, err - } - return w, nil -} - // ExecuteFaucetSCWallet implements the Faucet Smart contract for a given wallet func (t *Transaction) ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error { w, err := t.createFaucetSCWallet(walletStr, methodName, input) @@ -767,63 +713,11 @@ type vestingRequest struct { PoolID common.Key `json:"pool_id"` } -func (t *Transaction) vestingPoolTxn(function string, poolID string, - value uint64) error { - - return t.createSmartContractTxn(VestingSmartContractAddress, - function, vestingRequest{PoolID: common.Key(poolID)}, value) -} - -func (t *Transaction) VestingTrigger(poolID string) (err error) { - - err = t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { t.setNonceAndSubmit() }() - return -} - type VestingStopRequest struct { PoolID string `json:"pool_id"` Destination string `json:"destination"` } -func (t *Transaction) VestingStop(sr *VestingStopRequest) (err error) { - - err = t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_STOP, sr, 0) - if err != nil { - logging.Error(err) - return - } - go func() { t.setNonceAndSubmit() }() - return -} - -func (t *Transaction) VestingUnlock(poolID string) (err error) { - - err = t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { t.setNonceAndSubmit() }() - return -} - -func (t *Transaction) VestingDelete(poolID string) (err error) { - - err = t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { t.setNonceAndSubmit() }() - return -} - type scCollectReward struct { ProviderId string `json:"provider_id"` ProviderType int `json:"provider_type"` diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 1077a37a2..630501804 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -16,9 +16,12 @@ import ( "github.com/0chain/gosdk/core/block" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/core/encryption" + "github.com/0chain/gosdk/core/logger" "github.com/0chain/gosdk/core/node" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/core/util" + "github.com/0chain/gosdk/core/zcncrypto" + "go.uber.org/zap" ) const ( @@ -402,7 +405,7 @@ func newTransaction(cb TransactionCallback, txnFee string, nonce int64) (*Transa // - txnFee: Transaction fees (in SAS tokens) // - nonce: latest nonce of current wallet. please set it with 0 if you don't know the latest value func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (TransactionScheme, error) { - err = CheckConfig() + err := CheckConfig() if err != nil { return nil, err } @@ -412,7 +415,7 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac return nil, errors.New("", "auth url not set") } logging.Info("New transaction interface with auth") - return newTransactionWithAuth(cb, txnFeeRaw, nonce) + return newTransactionWithAuth(cb, txnFee, nonce) } logging.Info("New transaction interface") @@ -420,14 +423,66 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac return t, err } -// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { - v, err := parseCoinStr(val) +func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value string, opts ...FeeOption) error { + sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} + snBytes, err := json.Marshal(sn) if err != nil { + return errors.Wrap(err, "create smart contract failed due to invalid data") + } + + t.txn.TransactionType = transaction.TxnTypeSmartContract + t.txn.ToClientID = address + t.txn.TransactionData = string(snBytes) + t.txn.Value = value + + transactionFeeRaw, err := strconv.ParseUint(t.txn.TransactionFee, 0, 64) + if err != nil { + return err + } + + if transactionFeeRaw > 0 { + return nil + } + + tf := &TxnFeeOption{} + for _, opt := range opts { + opt(tf) + } + + if tf.noEstimateFee { + return nil + } + + // TODO: check if transaction is exempt to avoid unnecessary fee estimation + minFee, err := transaction.EstimateFee(t.txn, _config.chain.Miners, 0.2) + if err != nil { + logger.Logger.Error("failed estimate txn fee", + zap.Any("txn", t.txn.Hash), + zap.Error(err)) + return err + } + + t.txn.TransactionFee = strconv.FormatUint(minFee, 10) + + return nil +} + +func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, input []byte) (*zcncrypto.Wallet, error) { + w, err := getWallet(walletStr) + if err != nil { + fmt.Printf("Error while parsing the wallet. %v\n", err) return nil, err } + err = t.createSmartContractTxn(FaucetSmartContractAddress, methodName, input, "0") + if err != nil { + return nil, err + } + return w, nil +} - err = t.createSmartContractTxn(address, methodName, input, v) +// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain +func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { + err := t.createSmartContractTxn(address, methodName, input, val) if err != nil { return nil, err } @@ -481,14 +536,35 @@ func (t *Transaction) SendWithSignatureHash(toClientID string, val string, desc func (t *Transaction) VestingAdd(ar VestingAddRequest, value string) ( err error) { + err := t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_ADD, ar, value) + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} - v, err := parseCoinStr(value) +func (t *Transaction) VestingStop(sr *VestingStopRequest) (err error) { + err := t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_STOP, sr, "0") if err != nil { - return err + logging.Error(err) + return } + go func() { t.setNonceAndSubmit() }() + return +} - err = t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_ADD, ar, v) +func (t *Transaction) vestingPoolTxn(function string, poolID string, value string) error { + + return t.createSmartContractTxn(VestingSmartContractAddress, + function, vestingRequest{PoolID: common.Key(poolID)}, value) +} + +func (t *Transaction) VestingTrigger(poolID string) (err error) { + err := t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, "0") if err != nil { logging.Error(err) return @@ -497,19 +573,33 @@ func (t *Transaction) VestingAdd(ar VestingAddRequest, value string) ( return } -func (t *Transaction) MinerSCLock(providerId string, providerType int, lock string) error { +func (t *Transaction) VestingUnlock(poolID string) (err error) { + err := t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, "0") + if err != nil { + logging.Error(err) + return + } + go func() { t.setNonceAndSubmit() }() + return +} - lv, err := parseCoinStr(lock) +func (t *Transaction) VestingDelete(poolID string) (err error) { + err := t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, "0") if err != nil { - return err + logging.Error(err) + return } + go func() { t.setNonceAndSubmit() }() + return +} +func (t *Transaction) MinerSCLock(providerId string, providerType int, lock string) error { pr := stakePoolRequest{ ProviderType: providerType, ProviderID: providerId, } - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_LOCK, pr, lv) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_LOCK, pr, lock) if err != nil { logging.Error(err) return err @@ -524,7 +614,7 @@ func (t *Transaction) MinerSCUnlock(providerId string, providerType int) error { ProviderType: providerType, } err := t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_UNLOCK, pr, 0) + transaction.MINERSC_UNLOCK, pr, "0") if err != nil { logging.Error(err) return err @@ -540,7 +630,7 @@ func (t *Transaction) MinerSCCollectReward(providerId string, providerType int) } err := t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_COLLECT_REWARD, pr, 0) + transaction.MINERSC_COLLECT_REWARD, pr, "0") if err != nil { logging.Error(err) return err @@ -555,7 +645,7 @@ func (t *Transaction) StorageSCCollectReward(providerId string, providerType int ProviderType: providerType, } err := t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_COLLECT_REWARD, pr, 0) + transaction.STORAGESC_COLLECT_REWARD, pr, "0") if err != nil { logging.Error(err) return err @@ -569,10 +659,10 @@ func (t *Transaction) FinalizeAllocation(allocID string) (err error) { type finiRequest struct { AllocationID string `json:"allocation_id"` } - err = t.createSmartContractTxn(StorageSmartContractAddress, + err := t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_FINALIZE_ALLOCATION, &finiRequest{ AllocationID: allocID, - }, 0) + }, "0") if err != nil { logging.Error(err) return @@ -589,7 +679,7 @@ func (t *Transaction) CancelAllocation(allocID string) error { err := t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_CANCEL_ALLOCATION, &cancelRequest{ AllocationID: allocID, - }, 0) + }, "0") if err != nil { logging.Error(err) return err @@ -600,13 +690,8 @@ func (t *Transaction) CancelAllocation(allocID string) error { // CreateAllocation transaction. func (t *Transaction) CreateAllocation(car *CreateAllocationRequest, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_CREATE_ALLOCATION, car.toCreateAllocationSCInput(), lv) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_CREATE_ALLOCATION, car.toCreateAllocationSCInput(), lock) if err != nil { logging.Error(err) return err @@ -618,7 +703,7 @@ func (t *Transaction) CreateAllocation(car *CreateAllocationRequest, lock string // CreateReadPool for current user. func (t *Transaction) CreateReadPool() error { err := t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_CREATE_READ_POOL, nil, 0) + transaction.STORAGESC_CREATE_READ_POOL, nil, "0") if err != nil { logging.Error(err) return err @@ -632,10 +717,6 @@ func (t *Transaction) CreateReadPool() error { // allocation->blobber only. func (t *Transaction) ReadPoolLock(allocID, blobberID string, duration int64, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } type lockRequest struct { Duration time.Duration `json:"duration"` @@ -648,8 +729,8 @@ func (t *Transaction) ReadPoolLock(allocID, blobberID string, lr.AllocationID = allocID lr.BlobberID = blobberID - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_READ_POOL_LOCK, &lr, lv) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_READ_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) return err @@ -661,7 +742,7 @@ func (t *Transaction) ReadPoolLock(allocID, blobberID string, // ReadPoolUnlock for current user and given pool. func (t *Transaction) ReadPoolUnlock() error { err := t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_READ_POOL_UNLOCK, nil, 0) + transaction.STORAGESC_READ_POOL_UNLOCK, nil, "0") if err != nil { logging.Error(err) return err @@ -672,18 +753,13 @@ func (t *Transaction) ReadPoolUnlock() error { // StakePoolLock used to lock tokens in a stake pool of a blobber. func (t *Transaction) StakePoolLock(providerId string, providerType int, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - spr := stakePoolRequest{ ProviderType: providerType, ProviderID: providerId, } - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_STAKE_POOL_LOCK, &spr, lv) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_STAKE_POOL_LOCK, &spr, lock) if err != nil { logging.Error(err) return err @@ -699,7 +775,7 @@ func (t *Transaction) StakePoolUnlock(providerId string, providerType int) error ProviderID: providerId, } - err := t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, 0) + err := t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, "0") if err != nil { logging.Error(err) return err @@ -711,7 +787,7 @@ func (t *Transaction) StakePoolUnlock(providerId string, providerType int) error // UpdateBlobberSettings update settings of a blobber. func (t *Transaction) UpdateBlobberSettings(b Blobber) error { err := t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_BLOBBER_SETTINGS, b, 0) + transaction.STORAGESC_UPDATE_BLOBBER_SETTINGS, b, "0") if err != nil { logging.Error(err) return err @@ -723,11 +799,6 @@ func (t *Transaction) UpdateBlobberSettings(b Blobber) error { // UpdateAllocation transaction. func (t *Transaction) UpdateAllocation(allocID string, sizeDiff int64, expirationDiff int64, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - type updateAllocationRequest struct { ID string `json:"id"` // allocation id Size int64 `json:"size"` // difference @@ -739,8 +810,8 @@ func (t *Transaction) UpdateAllocation(allocID string, sizeDiff int64, uar.Size = sizeDiff uar.Expiration = expirationDiff - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_ALLOCATION, &uar, lv) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_UPDATE_ALLOCATION, &uar, lock) if err != nil { logging.Error(err) return err @@ -753,19 +824,14 @@ func (t *Transaction) UpdateAllocation(allocID string, sizeDiff int64, // duration. If blobberID is not empty, then tokens will be locked for given // allocation->blobber only. func (t *Transaction) WritePoolLock(allocID, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - var lr = struct { AllocationID string `json:"allocation_id"` }{ AllocationID: allocID, } - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_WRITE_POOL_LOCK, &lr, lv) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_WRITE_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) return err @@ -783,7 +849,7 @@ func (t *Transaction) WritePoolUnlock(allocID string) error { } err := t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_WRITE_POOL_UNLOCK, &ur, 0) + transaction.STORAGESC_WRITE_POOL_UNLOCK, &ur, "0") if err != nil { logging.Error(err) return err @@ -793,9 +859,8 @@ func (t *Transaction) WritePoolUnlock(allocID string) error { } func (t *Transaction) VestingUpdateConfig(vscc InputMap) (err error) { - - err = t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_UPDATE_SETTINGS, vscc, 0) + err := t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_UPDATE_SETTINGS, vscc, "0") if err != nil { logging.Error(err) return @@ -807,9 +872,8 @@ func (t *Transaction) VestingUpdateConfig(vscc InputMap) (err error) { // faucet smart contract func (t *Transaction) FaucetUpdateConfig(ip InputMap) (err error) { - - err = t.createSmartContractTxn(FaucetSmartContractAddress, - transaction.FAUCETSC_UPDATE_SETTINGS, ip, 0) + err := t.createSmartContractTxn(FaucetSmartContractAddress, + transaction.FAUCETSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -823,8 +887,8 @@ func (t *Transaction) FaucetUpdateConfig(ip InputMap) (err error) { // func (t *Transaction) MinerScUpdateConfig(ip InputMap) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_UPDATE_SETTINGS, ip, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -834,8 +898,8 @@ func (t *Transaction) MinerScUpdateConfig(ip InputMap) (err error) { } func (t *Transaction) MinerScUpdateGlobals(ip InputMap) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_UPDATE_GLOBALS, ip, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_UPDATE_GLOBALS, ip, "0") if err != nil { logging.Error(err) return @@ -845,8 +909,8 @@ func (t *Transaction) MinerScUpdateGlobals(ip InputMap) (err error) { } func (t *Transaction) StorageScUpdateConfig(ip InputMap) (err error) { - err = t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_SETTINGS, ip, 0) + err := t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -856,8 +920,8 @@ func (t *Transaction) StorageScUpdateConfig(ip InputMap) (err error) { } func (t *Transaction) ZCNSCUpdateGlobalConfig(ip InputMap) (err error) { - err = t.createSmartContractTxn(ZCNSCSmartContractAddress, - transaction.ZCNSC_UPDATE_GLOBAL_CONFIG, ip, 0) + err := t.createSmartContractTxn(ZCNSCSmartContractAddress, + transaction.ZCNSC_UPDATE_GLOBAL_CONFIG, ip, "0") if err != nil { logging.Error(err) return @@ -915,8 +979,8 @@ type simpleMiner struct { } func (t *Transaction) MinerSCMinerSettings(info MinerSCMinerInfo) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_MINER_SETTINGS, info, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_MINER_SETTINGS, info, "0") if err != nil { logging.Error(err) return @@ -926,8 +990,8 @@ func (t *Transaction) MinerSCMinerSettings(info MinerSCMinerInfo) (err error) { } func (t *Transaction) MinerSCSharderSettings(info MinerSCMinerInfo) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_SHARDER_SETTINGS, info, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_SHARDER_SETTINGS, info, "0") if err != nil { logging.Error(err) return @@ -937,8 +1001,8 @@ func (t *Transaction) MinerSCSharderSettings(info MinerSCMinerInfo) (err error) } func (t *Transaction) MinerSCDeleteMiner(info MinerSCMinerInfo) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_MINER_DELETE, info, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_MINER_DELETE, info, "0") if err != nil { logging.Error(err) return @@ -948,8 +1012,8 @@ func (t *Transaction) MinerSCDeleteMiner(info MinerSCMinerInfo) (err error) { } func (t *Transaction) MinerSCDeleteSharder(info MinerSCMinerInfo) (err error) { - err = t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_SHARDER_DELETE, info, 0) + err := t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_SHARDER_DELETE, info, "0") if err != nil { logging.Error(err) return @@ -982,7 +1046,7 @@ func (a *authorizerNode) GetID() string { } func (t *Transaction) ZCNSCUpdateAuthorizerConfig(ip AuthorizerNode) (err error) { - err = t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, 0) + err := t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, "0") if err != nil { logging.Error(err) return @@ -1093,7 +1157,7 @@ func (t *Transaction) Verify() error { } func (t *Transaction) ZCNSCAddAuthorizer(ip AddAuthorizerPayload) (err error) { - err = t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, 0) + err := t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, "0") if err != nil { logging.Error(err) return @@ -1431,24 +1495,7 @@ func toMobileBlock(b *block.Block) *Block { lb.txns = make([]*transaction.Transaction, len(b.Txns)) for i, txn := range b.Txns { - lb.txns[i] = &transaction.Transaction{ - Hash: txn.Hash, - Version: txn.Version, - ClientID: txn.ClientID, - PublicKey: txn.PublicKey, - ToClientID: txn.ToClientID, - ChainID: txn.ChainID, - TransactionData: txn.TransactionData, - Signature: txn.Signature, - CreationDate: txn.CreationDate, - TransactionType: txn.TransactionType, - TransactionOutput: txn.TransactionOutput, - TransactionNonce: txn.TransactionNonce, - OutputHash: txn.OutputHash, - Status: txn.Status, - Value: strconv.FormatUint(txn.Value, 10), - TransactionFee: strconv.FormatUint(txn.TransactionFee, 10), - } + lb.txns[i] = txn } return lb diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 4aa31c9cf..2734a3587 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -20,12 +20,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { - v, err := parseCoinStr(val) - if err != nil { - return nil, err - } - - err = ta.t.createSmartContractTxn(address, methodName, input, v, feeOpts...) + err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) if err != nil { return nil, err } @@ -51,13 +46,8 @@ func (ta *TransactionWithAuth) Send(toClientID string, val string, desc string) } func (ta *TransactionWithAuth) VestingAdd(ar VestingAddRequest, value string) error { - v, err := parseCoinStr(value) - if err != nil { - return err - } - - err = ta.t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_ADD, ar, v) + err := ta.t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_ADD, ar, value) if err != nil { logging.Error(err) return err @@ -67,18 +57,13 @@ func (ta *TransactionWithAuth) VestingAdd(ar VestingAddRequest, value string) er } func (ta *TransactionWithAuth) MinerSCLock(providerId string, providerType int, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - pr := stakePoolRequest{ ProviderType: providerType, ProviderID: providerId, } - err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_LOCK, &pr, lv) + err := ta.t.createSmartContractTxn(MinerSmartContractAddress, + transaction.MINERSC_LOCK, &pr, lock) if err != nil { logging.Error(err) return err @@ -93,7 +78,7 @@ func (ta *TransactionWithAuth) MinerSCUnlock(providerId string, providerType int ProviderType: providerType, } err := ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_LOCK, pr, 0) + transaction.MINERSC_LOCK, pr, "0") if err != nil { logging.Error(err) return err @@ -110,7 +95,7 @@ func (ta *TransactionWithAuth) FinalizeAllocation(allocID string) error { err := ta.t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_FINALIZE_ALLOCATION, &finiRequest{ AllocationID: allocID, - }, 0) + }, "0") if err != nil { logging.Error(err) return err @@ -127,7 +112,7 @@ func (ta *TransactionWithAuth) CancelAllocation(allocID string) error { err := ta.t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_CANCEL_ALLOCATION, &cancelRequest{ AllocationID: allocID, - }, 0) + }, "0") if err != nil { logging.Error(err) return err @@ -139,13 +124,8 @@ func (ta *TransactionWithAuth) CancelAllocation(allocID string) error { // CreateAllocation transaction. func (ta *TransactionWithAuth) CreateAllocation(car *CreateAllocationRequest, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - - err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_CREATE_ALLOCATION, car, lv) + err := ta.t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_CREATE_ALLOCATION, car, lock) if err != nil { logging.Error(err) return err @@ -157,7 +137,7 @@ func (ta *TransactionWithAuth) CreateAllocation(car *CreateAllocationRequest, // CreateReadPool for current user. func (ta *TransactionWithAuth) CreateReadPool() error { if err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_CREATE_READ_POOL, nil, 0); err != nil { + transaction.STORAGESC_CREATE_READ_POOL, nil, "0"); err != nil { logging.Error(err) return err } @@ -170,11 +150,6 @@ func (ta *TransactionWithAuth) CreateReadPool() error { // allocation->blobber only. func (ta *TransactionWithAuth) ReadPoolLock(allocID, blobberID string, duration int64, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - type lockRequest struct { Duration time.Duration `json:"duration"` AllocationID string `json:"allocation_id"` @@ -187,7 +162,7 @@ func (ta *TransactionWithAuth) ReadPoolLock(allocID, blobberID string, lr.BlobberID = blobberID err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_READ_POOL_LOCK, &lr, lv) + transaction.STORAGESC_READ_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) return err @@ -199,7 +174,7 @@ func (ta *TransactionWithAuth) ReadPoolLock(allocID, blobberID string, // ReadPoolUnlock for current user and given pool. func (ta *TransactionWithAuth) ReadPoolUnlock() error { if err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_READ_POOL_UNLOCK, nil, 0); err != nil { + transaction.STORAGESC_READ_POOL_UNLOCK, nil, "0"); err != nil { logging.Error(err) return err } @@ -210,11 +185,6 @@ func (ta *TransactionWithAuth) ReadPoolUnlock() error { // StakePoolLock used to lock tokens in a stake pool of a blobber. func (ta *TransactionWithAuth) StakePoolLock(providerId string, providerType int, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - type stakePoolRequest struct { ProviderType int `json:"provider_type,omitempty"` ProviderID string `json:"provider_id,omitempty"` @@ -224,8 +194,8 @@ func (ta *TransactionWithAuth) StakePoolLock(providerId string, providerType int ProviderType: providerType, ProviderID: providerId, } - err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_STAKE_POOL_LOCK, &spr, lv) + err := ta.t.createSmartContractTxn(StorageSmartContractAddress, + transaction.STORAGESC_STAKE_POOL_LOCK, &spr, lock) if err != nil { logging.Error(err) return err @@ -242,7 +212,7 @@ func (ta *TransactionWithAuth) StakePoolUnlock(providerId string, providerType i } if err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, 0); err != nil { + transaction.STORAGESC_STAKE_POOL_UNLOCK, &spr, "0"); err != nil { logging.Error(err) return err } @@ -253,7 +223,7 @@ func (ta *TransactionWithAuth) StakePoolUnlock(providerId string, providerType i // UpdateBlobberSettings update settings of a blobber. func (ta *TransactionWithAuth) UpdateBlobberSettings(blob Blobber) error { if err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_BLOBBER_SETTINGS, blob, 0); err != nil { + transaction.STORAGESC_UPDATE_BLOBBER_SETTINGS, blob, "0"); err != nil { logging.Error(err) return err } @@ -264,11 +234,6 @@ func (ta *TransactionWithAuth) UpdateBlobberSettings(blob Blobber) error { // UpdateAllocation transaction. func (ta *TransactionWithAuth) UpdateAllocation(allocID string, sizeDiff int64, expirationDiff int64, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - type updateAllocationRequest struct { ID string `json:"id"` // allocation id Size int64 `json:"size"` // difference @@ -281,7 +246,7 @@ func (ta *TransactionWithAuth) UpdateAllocation(allocID string, sizeDiff int64, uar.Expiration = expirationDiff err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_ALLOCATION, &uar, lv) + transaction.STORAGESC_UPDATE_ALLOCATION, &uar, lock) if err != nil { logging.Error(err) return err @@ -294,11 +259,6 @@ func (ta *TransactionWithAuth) UpdateAllocation(allocID string, sizeDiff int64, // duration. If blobberID is not empty, then tokens will be locked for given // allocation->blobber only. func (ta *TransactionWithAuth) WritePoolLock(allocID, lock string) error { - lv, err := parseCoinStr(lock) - if err != nil { - return err - } - var lr = struct { AllocationID string `json:"allocation_id"` }{ @@ -306,7 +266,7 @@ func (ta *TransactionWithAuth) WritePoolLock(allocID, lock string) error { } err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_WRITE_POOL_LOCK, &lr, lv) + transaction.STORAGESC_WRITE_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) return err @@ -324,7 +284,7 @@ func (ta *TransactionWithAuth) WritePoolUnlock(allocID string) error { } if err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_WRITE_POOL_UNLOCK, &ur, 0); err != nil { + transaction.STORAGESC_WRITE_POOL_UNLOCK, &ur, "0"); err != nil { logging.Error(err) return err } @@ -338,7 +298,7 @@ func (ta *TransactionWithAuth) MinerSCCollectReward(providerId string, providerT ProviderType: providerType, } err := ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_COLLECT_REWARD, pr, 0) + transaction.MINERSC_COLLECT_REWARD, pr, "0") if err != nil { logging.Error(err) return err @@ -353,7 +313,7 @@ func (ta *TransactionWithAuth) StorageSCCollectReward(providerId string, provide ProviderType: providerType, } err := ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_COLLECT_REWARD, pr, 0) + transaction.STORAGESC_COLLECT_REWARD, pr, "0") if err != nil { logging.Error(err) return err @@ -364,7 +324,7 @@ func (ta *TransactionWithAuth) StorageSCCollectReward(providerId string, provide func (ta *TransactionWithAuth) VestingUpdateConfig(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_UPDATE_SETTINGS, ip, 0) + transaction.VESTING_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -377,7 +337,7 @@ func (ta *TransactionWithAuth) VestingUpdateConfig(ip InputMap) (err error) { func (ta *TransactionWithAuth) FaucetUpdateConfig(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(FaucetSmartContractAddress, - transaction.FAUCETSC_UPDATE_SETTINGS, ip, 0) + transaction.FAUCETSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -388,7 +348,7 @@ func (ta *TransactionWithAuth) FaucetUpdateConfig(ip InputMap) (err error) { func (ta *TransactionWithAuth) MinerScUpdateConfig(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_UPDATE_SETTINGS, ip, 0) + transaction.MINERSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -399,7 +359,7 @@ func (ta *TransactionWithAuth) MinerScUpdateConfig(ip InputMap) (err error) { func (ta *TransactionWithAuth) MinerScUpdateGlobals(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_UPDATE_GLOBALS, ip, 0) + transaction.MINERSC_UPDATE_GLOBALS, ip, "0") if err != nil { logging.Error(err) return @@ -410,7 +370,7 @@ func (ta *TransactionWithAuth) MinerScUpdateGlobals(ip InputMap) (err error) { func (ta *TransactionWithAuth) StorageScUpdateConfig(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(StorageSmartContractAddress, - transaction.STORAGESC_UPDATE_SETTINGS, ip, 0) + transaction.STORAGESC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) return @@ -421,7 +381,7 @@ func (ta *TransactionWithAuth) StorageScUpdateConfig(ip InputMap) (err error) { func (ta *TransactionWithAuth) ZCNSCUpdateGlobalConfig(ip InputMap) (err error) { err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, - transaction.ZCNSC_UPDATE_GLOBAL_CONFIG, ip, 0) + transaction.ZCNSC_UPDATE_GLOBAL_CONFIG, ip, "0") if err != nil { logging.Error(err) return @@ -436,9 +396,8 @@ func (ta *TransactionWithAuth) GetVerifyConfirmationStatus() int { func (ta *TransactionWithAuth) MinerSCMinerSettings(info MinerSCMinerInfo) ( err error) { - err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_MINER_SETTINGS, info, 0) + transaction.MINERSC_MINER_SETTINGS, info, "0") if err != nil { logging.Error(err) return @@ -451,7 +410,7 @@ func (ta *TransactionWithAuth) MinerSCSharderSettings(info MinerSCMinerInfo) ( err error) { err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_SHARDER_SETTINGS, info, 0) + transaction.MINERSC_SHARDER_SETTINGS, info, "0") if err != nil { logging.Error(err) return @@ -464,7 +423,7 @@ func (ta *TransactionWithAuth) MinerSCDeleteMiner(info MinerSCMinerInfo) ( err error) { err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_MINER_DELETE, info, 0) + transaction.MINERSC_MINER_DELETE, info, "0") if err != nil { logging.Error(err) return @@ -477,7 +436,7 @@ func (ta *TransactionWithAuth) MinerSCDeleteSharder(info MinerSCMinerInfo) ( err error) { err = ta.t.createSmartContractTxn(MinerSmartContractAddress, - transaction.MINERSC_SHARDER_DELETE, info, 0) + transaction.MINERSC_SHARDER_DELETE, info, "0") if err != nil { logging.Error(err) return @@ -487,7 +446,7 @@ func (ta *TransactionWithAuth) MinerSCDeleteSharder(info MinerSCMinerInfo) ( } func (ta *TransactionWithAuth) ZCNSCUpdateAuthorizerConfig(ip AuthorizerNode) (err error) { - err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, 0) + err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, "0") if err != nil { logging.Error(err) return @@ -497,7 +456,7 @@ func (ta *TransactionWithAuth) ZCNSCUpdateAuthorizerConfig(ip AuthorizerNode) (e } func (ta *TransactionWithAuth) ZCNSCAddAuthorizer(ip AddAuthorizerPayload) (err error) { - err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, 0) + err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, "0") if err != nil { logging.Error(err) return @@ -507,7 +466,7 @@ func (ta *TransactionWithAuth) ZCNSCAddAuthorizer(ip AddAuthorizerPayload) (err } func (ta *TransactionWithAuth) ZCNSCAuthorizerHealthCheck(ip *AuthorizerHealthCheckPayload) (err error) { - err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_AUTHORIZER_HEALTH_CHECK, ip, 0) + err = ta.t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_AUTHORIZER_HEALTH_CHECK, ip, "0") if err != nil { logging.Error(err) return From 6b7851e6baad7be1abf31718e0ed140e6c90ac9a Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 02:01:09 +0200 Subject: [PATCH 16/43] fix: fixed bugs --- zcncore/transaction_mobile.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 630501804..63d2db0f0 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -536,7 +536,7 @@ func (t *Transaction) SendWithSignatureHash(toClientID string, val string, desc func (t *Transaction) VestingAdd(ar VestingAddRequest, value string) ( err error) { - err := t.createSmartContractTxn(VestingSmartContractAddress, + err = t.createSmartContractTxn(VestingSmartContractAddress, transaction.VESTING_ADD, ar, value) if err != nil { logging.Error(err) @@ -547,7 +547,7 @@ func (t *Transaction) VestingAdd(ar VestingAddRequest, value string) ( } func (t *Transaction) VestingStop(sr *VestingStopRequest) (err error) { - err := t.createSmartContractTxn(VestingSmartContractAddress, + err = t.createSmartContractTxn(VestingSmartContractAddress, transaction.VESTING_STOP, sr, "0") if err != nil { logging.Error(err) @@ -564,7 +564,7 @@ func (t *Transaction) vestingPoolTxn(function string, poolID string, value strin } func (t *Transaction) VestingTrigger(poolID string) (err error) { - err := t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, "0") + err = t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, "0") if err != nil { logging.Error(err) return @@ -574,7 +574,7 @@ func (t *Transaction) VestingTrigger(poolID string) (err error) { } func (t *Transaction) VestingUnlock(poolID string) (err error) { - err := t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, "0") + err = t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, "0") if err != nil { logging.Error(err) return @@ -584,7 +584,7 @@ func (t *Transaction) VestingUnlock(poolID string) (err error) { } func (t *Transaction) VestingDelete(poolID string) (err error) { - err := t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, "0") + err = t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, "0") if err != nil { logging.Error(err) return @@ -859,7 +859,7 @@ func (t *Transaction) WritePoolUnlock(allocID string) error { } func (t *Transaction) VestingUpdateConfig(vscc InputMap) (err error) { - err := t.createSmartContractTxn(VestingSmartContractAddress, + err = t.createSmartContractTxn(VestingSmartContractAddress, transaction.VESTING_UPDATE_SETTINGS, vscc, "0") if err != nil { logging.Error(err) @@ -872,7 +872,7 @@ func (t *Transaction) VestingUpdateConfig(vscc InputMap) (err error) { // faucet smart contract func (t *Transaction) FaucetUpdateConfig(ip InputMap) (err error) { - err := t.createSmartContractTxn(FaucetSmartContractAddress, + err = t.createSmartContractTxn(FaucetSmartContractAddress, transaction.FAUCETSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) @@ -887,7 +887,7 @@ func (t *Transaction) FaucetUpdateConfig(ip InputMap) (err error) { // func (t *Transaction) MinerScUpdateConfig(ip InputMap) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) @@ -898,7 +898,7 @@ func (t *Transaction) MinerScUpdateConfig(ip InputMap) (err error) { } func (t *Transaction) MinerScUpdateGlobals(ip InputMap) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_UPDATE_GLOBALS, ip, "0") if err != nil { logging.Error(err) @@ -909,7 +909,7 @@ func (t *Transaction) MinerScUpdateGlobals(ip InputMap) (err error) { } func (t *Transaction) StorageScUpdateConfig(ip InputMap) (err error) { - err := t.createSmartContractTxn(StorageSmartContractAddress, + err = t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_UPDATE_SETTINGS, ip, "0") if err != nil { logging.Error(err) @@ -920,7 +920,7 @@ func (t *Transaction) StorageScUpdateConfig(ip InputMap) (err error) { } func (t *Transaction) ZCNSCUpdateGlobalConfig(ip InputMap) (err error) { - err := t.createSmartContractTxn(ZCNSCSmartContractAddress, + err = t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_GLOBAL_CONFIG, ip, "0") if err != nil { logging.Error(err) @@ -979,7 +979,7 @@ type simpleMiner struct { } func (t *Transaction) MinerSCMinerSettings(info MinerSCMinerInfo) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_MINER_SETTINGS, info, "0") if err != nil { logging.Error(err) @@ -990,7 +990,7 @@ func (t *Transaction) MinerSCMinerSettings(info MinerSCMinerInfo) (err error) { } func (t *Transaction) MinerSCSharderSettings(info MinerSCMinerInfo) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_SHARDER_SETTINGS, info, "0") if err != nil { logging.Error(err) @@ -1001,7 +1001,7 @@ func (t *Transaction) MinerSCSharderSettings(info MinerSCMinerInfo) (err error) } func (t *Transaction) MinerSCDeleteMiner(info MinerSCMinerInfo) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_MINER_DELETE, info, "0") if err != nil { logging.Error(err) @@ -1012,7 +1012,7 @@ func (t *Transaction) MinerSCDeleteMiner(info MinerSCMinerInfo) (err error) { } func (t *Transaction) MinerSCDeleteSharder(info MinerSCMinerInfo) (err error) { - err := t.createSmartContractTxn(MinerSmartContractAddress, + err = t.createSmartContractTxn(MinerSmartContractAddress, transaction.MINERSC_SHARDER_DELETE, info, "0") if err != nil { logging.Error(err) @@ -1046,7 +1046,7 @@ func (a *authorizerNode) GetID() string { } func (t *Transaction) ZCNSCUpdateAuthorizerConfig(ip AuthorizerNode) (err error) { - err := t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, "0") + err = t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_UPDATE_AUTHORIZER_CONFIG, ip, "0") if err != nil { logging.Error(err) return @@ -1157,7 +1157,7 @@ func (t *Transaction) Verify() error { } func (t *Transaction) ZCNSCAddAuthorizer(ip AddAuthorizerPayload) (err error) { - err := t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, "0") + err = t.createSmartContractTxn(ZCNSCSmartContractAddress, transaction.ZCNSC_ADD_AUTHORIZER, ip, "0") if err != nil { logging.Error(err) return From 6f74e67f8f89d1a258e797ffc2bd7d00e9b5a1a8 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 02:09:08 +0200 Subject: [PATCH 17/43] fix: fixed bugs --- zcncore/transaction_mobile.go | 2 +- zcncore/transactionauth_mobile.go | 46 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 63d2db0f0..d087f8341 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -659,7 +659,7 @@ func (t *Transaction) FinalizeAllocation(allocID string) (err error) { type finiRequest struct { AllocationID string `json:"allocation_id"` } - err := t.createSmartContractTxn(StorageSmartContractAddress, + err = t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_FINALIZE_ALLOCATION, &finiRequest{ AllocationID: allocID, }, "0") diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 2734a3587..36bf0f510 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -161,7 +161,7 @@ func (ta *TransactionWithAuth) ReadPoolLock(allocID, blobberID string, lr.AllocationID = allocID lr.BlobberID = blobberID - err = ta.t.createSmartContractTxn(StorageSmartContractAddress, + err := ta.t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_READ_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) @@ -245,7 +245,7 @@ func (ta *TransactionWithAuth) UpdateAllocation(allocID string, sizeDiff int64, uar.Size = sizeDiff uar.Expiration = expirationDiff - err = ta.t.createSmartContractTxn(StorageSmartContractAddress, + err := ta.t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_UPDATE_ALLOCATION, &uar, lock) if err != nil { logging.Error(err) @@ -474,3 +474,45 @@ func (ta *TransactionWithAuth) ZCNSCAuthorizerHealthCheck(ip *AuthorizerHealthCh go ta.t.setNonceAndSubmit() return } + +func (ta *TransactionWithAuth) VestingTrigger(poolID string) (err error) { + err = ta.t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, "0") + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingStop(sr *VestingStopRequest) (err error) { + err = ta.t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_STOP, sr, "0") + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingUnlock(poolID string) (err error) { + + err = ta.t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, "0") + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingDelete(poolID string) (err error) { + err = ta.t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, "0") + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} From 05bcc57759ac1a332bc95d058a83b1aaa4501f4c Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 02:14:09 +0200 Subject: [PATCH 18/43] fix: fixed bugs --- zcncore/transactionauth.go | 46 +++++++++++++++++++++++++++++++ zcncore/transactionauth_base.go | 46 ------------------------------- zcncore/transactionauth_mobile.go | 2 +- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/zcncore/transactionauth.go b/zcncore/transactionauth.go index 824cab27e..631be73b7 100644 --- a/zcncore/transactionauth.go +++ b/zcncore/transactionauth.go @@ -615,3 +615,49 @@ func (ta *TransactionWithAuth) ZCNSCCollectReward(providerId string, providerTyp go func() { ta.t.setNonceAndSubmit() }() return err } + +// ========================================================================== // +// vesting pool // +// ========================================================================== // + +func (ta *TransactionWithAuth) VestingTrigger(poolID string) (err error) { + err = ta.t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingStop(sr *VestingStopRequest) (err error) { + err = ta.t.createSmartContractTxn(VestingSmartContractAddress, + transaction.VESTING_STOP, sr, 0) + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingUnlock(poolID string) (err error) { + + err = ta.t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} + +func (ta *TransactionWithAuth) VestingDelete(poolID string) (err error) { + err = ta.t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, 0) + if err != nil { + logging.Error(err) + return + } + go func() { ta.submitTxn() }() + return +} diff --git a/zcncore/transactionauth_base.go b/zcncore/transactionauth_base.go index 7f8b8848c..1217445b4 100644 --- a/zcncore/transactionauth_base.go +++ b/zcncore/transactionauth_base.go @@ -192,52 +192,6 @@ func (ta *TransactionWithAuth) GetTransactionNonce() int64 { return ta.t.txn.TransactionNonce } -// ========================================================================== // -// vesting pool // -// ========================================================================== // - -func (ta *TransactionWithAuth) VestingTrigger(poolID string) (err error) { - err = ta.t.vestingPoolTxn(transaction.VESTING_TRIGGER, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { ta.submitTxn() }() - return -} - -func (ta *TransactionWithAuth) VestingStop(sr *VestingStopRequest) (err error) { - err = ta.t.createSmartContractTxn(VestingSmartContractAddress, - transaction.VESTING_STOP, sr, 0) - if err != nil { - logging.Error(err) - return - } - go func() { ta.submitTxn() }() - return -} - -func (ta *TransactionWithAuth) VestingUnlock(poolID string) (err error) { - - err = ta.t.vestingPoolTxn(transaction.VESTING_UNLOCK, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { ta.submitTxn() }() - return -} - -func (ta *TransactionWithAuth) VestingDelete(poolID string) (err error) { - err = ta.t.vestingPoolTxn(transaction.VESTING_DELETE, poolID, 0) - if err != nil { - logging.Error(err) - return - } - go func() { ta.submitTxn() }() - return -} - // // miner sc // diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 36bf0f510..04fcd35ef 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -265,7 +265,7 @@ func (ta *TransactionWithAuth) WritePoolLock(allocID, lock string) error { AllocationID: allocID, } - err = ta.t.createSmartContractTxn(StorageSmartContractAddress, + err := ta.t.createSmartContractTxn(StorageSmartContractAddress, transaction.STORAGESC_WRITE_POOL_LOCK, &lr, lock) if err != nil { logging.Error(err) From 7a8a0c703a6038935069af74d514b1d95512e07e Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 02:18:46 +0200 Subject: [PATCH 19/43] fix: fixed bugs --- zcncore/transaction_mobile.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index d087f8341..69df706b3 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -16,12 +16,10 @@ import ( "github.com/0chain/gosdk/core/block" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/core/encryption" - "github.com/0chain/gosdk/core/logger" "github.com/0chain/gosdk/core/node" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/core/util" "github.com/0chain/gosdk/core/zcncrypto" - "go.uber.org/zap" ) const ( @@ -456,9 +454,6 @@ func (t *Transaction) createSmartContractTxn(address, methodName string, input i // TODO: check if transaction is exempt to avoid unnecessary fee estimation minFee, err := transaction.EstimateFee(t.txn, _config.chain.Miners, 0.2) if err != nil { - logger.Logger.Error("failed estimate txn fee", - zap.Any("txn", t.txn.Hash), - zap.Error(err)) return err } From 6ab67d1f06b73604b88e6e7e791276238fad5976 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 15:45:50 +0200 Subject: [PATCH 20/43] fix: debug --- zcncore/transaction_mobile.go | 7 +++++++ zcncore/transactionauth_mobile.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 69df706b3..55e80b3db 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,6 +53,8 @@ var ( ) type TransactionCommon interface { + ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) + ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) // Send implements sending token to a given clientid @@ -475,6 +477,11 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, return w, nil } +// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain +func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { + return nil, nil +} + // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { err := t.createSmartContractTxn(address, methodName, input, val) diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 04fcd35ef..737bcf68d 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -18,6 +18,11 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) return ta, err } +// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { + return nil, nil +} + func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) From 73c9532ae9ed7dfaf5085d83cf2860fef57b4713 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 15:56:23 +0200 Subject: [PATCH 21/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 55e80b3db..97794f0b0 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { - return nil, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { + return nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 737bcf68d..36421f468 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string) (*transaction.Transaction, error) { - return nil, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { + return nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 7faa53b991f52fe735836a083835ca4d5e3be262 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 16:05:57 +0200 Subject: [PATCH 22/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 97794f0b0..b85e63570 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error + ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { - return nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { + return nil, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 36421f468..6dd5138f5 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { - return nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { + return nil, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From e8230c2988f32f3d843f8c85f5aca64329d63986 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 19:48:41 +0200 Subject: [PATCH 23/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index b85e63570..bee1082c4 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { - return nil, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 6dd5138f5..a517ca6bd 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { - return nil, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 54226fef3794c60ec83ed35263f051599a17bfe0 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 19:55:01 +0200 Subject: [PATCH 24/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index bee1082c4..937627925 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,7 +478,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) { return transaction.Transaction{}, nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index a517ca6bd..5c1e67c35 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,7 +19,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) (transaction.Transaction, error) { +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) { return transaction.Transaction{}, nil } From 7913d694966e664cd095fe947f73c6cee8f5c1ec Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 20:06:20 +0200 Subject: [PATCH 25/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 937627925..6cbe1ba74 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, val string) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string) error { + return nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 5c1e67c35..d412625eb 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string) error { + return nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 3f7e13d9c510a1373aa0d0f87d60de6d5768eba8 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 20:17:08 +0200 Subject: [PATCH 26/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 6cbe1ba74..97794f0b0 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string) error + ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,7 +478,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string) error { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { return nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index d412625eb..36421f468 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,7 +19,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string) error { +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { return nil } From 06ad1393075f37ca210bb285009866de052e1dd4 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 20:29:33 +0200 Subject: [PATCH 27/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 97794f0b0..cf2a80c3d 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error + ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,7 +478,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error { return nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 36421f468..f15f38959 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,7 +19,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { +func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error { return nil } From 27ef5fbff7fb3e044687cdf1cfc9632d16161077 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 20:38:20 +0200 Subject: [PATCH 28/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index cf2a80c3d..cd6438aca 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error + ExecuteSmartContracts(address, methodName string, val string, input interface{}) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,7 +478,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input interface{}) error { return nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index f15f38959..34d2929ce 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,7 +19,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address, methodName string, val string, feeOpts ...FeeOption) error { +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input interface{}) error { return nil } From c7dc171e79822b2647ba4b212cc5dfa5f18c36c0 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 20:49:04 +0200 Subject: [PATCH 29/43] fix: debug --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index cd6438aca..4657bccb4 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input interface{}) error + ExecuteSmartContracts(address, methodName string, val string, input string) error ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,7 +478,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input interface{}) error { +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) error { return nil } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 34d2929ce..c5ea25735 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,7 +19,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input interface{}) error { +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) error { return nil } From 4d031a3d90f5ad4ba043e5845d46b8de4617db7c Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 21:15:24 +0200 Subject: [PATCH 30/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 4657bccb4..e7ce41c5c 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input string) error + ExecuteSmartContracts(address, methodName string, val string, input string) (*transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) error { - return nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (*transaction.Transaction, error) { + return nil, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index c5ea25735..3671c1b6e 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) error { - return nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (*transaction.Transaction, error) { + return nil, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From ac48404b0997fbd06ef6bbe6d24c60c975e64bb0 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 21:28:37 +0200 Subject: [PATCH 31/43] fix: debug --- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index e7ce41c5c..de17ca836 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input string) (*transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.Transaction, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (*transaction.Transaction, error) { - return nil, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 3671c1b6e..71dae4d0b 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (*transaction.Transaction, error) { - return nil, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (transaction.Transaction, error) { + return transaction.Transaction{}, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From dfd8719a5b4a6bcc34030f871a49de69b47a46d0 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 21:41:14 +0200 Subject: [PATCH 32/43] fix: debug --- core/transaction/transaction_mobile.go | 101 ++++++++++++------------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 3119429e5..5bfd4716f 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -3,11 +3,6 @@ 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"` @@ -28,55 +23,55 @@ type Transaction struct { 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"` -} +// // 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 - } +// 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 - } +// 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, - } +// 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) -} +// return json.Marshal(wrapper) +// } From b8f68c92642a4d19aad06a4662b3a2e53af35a3d Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 21:47:47 +0200 Subject: [PATCH 33/43] fix: debug --- core/transaction/transaction_mobile.go | 6 ++++++ zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 5bfd4716f..e2271fe68 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -23,6 +23,12 @@ type Transaction struct { Status int `json:"transaction_status"` } +// Transaction represents entity that encapsulates the transaction related data and metadata. +type TransactionTest struct { + Value string `json:"transaction_value"` + TransactionFee string `json:"transaction_fee"` +} + // // TransactionWrapper represents wrapper for mobile transaction entity. // type TransactionWrapper struct { // Hash string `json:"hash,omitempty"` diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index de17ca836..3f9d53aa2 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.Transaction, error) + ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.TransactionTest, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +478,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.TransactionTest, error) { + return transaction.TransactionTest{}, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 71dae4d0b..760d98c04 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (transaction.Transaction, error) { - return transaction.Transaction{}, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (transaction.TransactionTest, error) { + return transaction.TransactionTest{}, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 335d65f96a2010f62182f6f60bc5a8a56f665dbd Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 22:04:53 +0200 Subject: [PATCH 34/43] fix: debug --- core/transaction/transaction_mobile.go | 6 ------ zcncore/transaction_mobile.go | 12 +++++++++--- zcncore/transactionauth_mobile.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index e2271fe68..5bfd4716f 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -23,12 +23,6 @@ type Transaction struct { Status int `json:"transaction_status"` } -// Transaction represents entity that encapsulates the transaction related data and metadata. -type TransactionTest struct { - Value string `json:"transaction_value"` - TransactionFee string `json:"transaction_fee"` -} - // // TransactionWrapper represents wrapper for mobile transaction entity. // type TransactionWrapper struct { // Hash string `json:"hash,omitempty"` diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 3f9d53aa2..9b1409d7e 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -52,8 +52,14 @@ var ( _ TransactionScheme = (*TransactionWithAuth)(nil) ) +// Transaction represents entity that encapsulates the transaction related data and metadata. +type TransactionTest struct { + Value string `json:"transaction_value"` + TransactionFee string `json:"transaction_fee"` +} + type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.TransactionTest, error) + ExecuteSmartContracts(address, methodName string, val string, input string) (TransactionTest, error) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) @@ -478,8 +484,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (transaction.TransactionTest, error) { - return transaction.TransactionTest{}, nil +func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (TransactionTest, error) { + return TransactionTest{}, nil } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 760d98c04..569ab1888 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -19,8 +19,8 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (transaction.TransactionTest, error) { - return transaction.TransactionTest{}, nil +func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (TransactionTest, error) { + return TransactionTest{}, nil } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, From 1c2b15ef01ca00bafec71f150c718296fc2af2c6 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Tue, 24 Sep 2024 22:11:40 +0200 Subject: [PATCH 35/43] fix: debug --- zcncore/transaction_mobile.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 9b1409d7e..9a2fcfe10 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -54,8 +54,6 @@ var ( // Transaction represents entity that encapsulates the transaction related data and metadata. type TransactionTest struct { - Value string `json:"transaction_value"` - TransactionFee string `json:"transaction_fee"` } type TransactionCommon interface { From 2451ee768fe59d552b7b706162382403fd648d52 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 00:52:36 +0200 Subject: [PATCH 36/43] fix: debug --- core/transaction/transaction_mobile.go | 101 +++++++++++++------------ mobilesdk/zcn/smartcontract.go | 2 +- zboxcore/sdk/transaction_mobile.go | 4 +- zcncore/transaction_mobile.go | 26 ++----- zcncore/transactionauth_mobile.go | 11 ++- 5 files changed, 70 insertions(+), 74 deletions(-) diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 5bfd4716f..3119429e5 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -3,6 +3,11 @@ 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"` @@ -23,55 +28,55 @@ type Transaction struct { 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"` -// } +// 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 -// } +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 -// } + 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, -// } + 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) -// } + return json.Marshal(wrapper) +} diff --git a/mobilesdk/zcn/smartcontract.go b/mobilesdk/zcn/smartcontract.go index 2ecaaad51..7df9025c8 100644 --- a/mobilesdk/zcn/smartcontract.go +++ b/mobilesdk/zcn/smartcontract.go @@ -26,7 +26,7 @@ func ExecuteSmartContract(address, methodName, input, sasToken string) (string, wg.Add(1) - _, err = txn.ExecuteSmartContract(address, methodName, input, sasToken) + err = txn.ExecuteSmartContract(address, methodName, input, sasToken) if err != nil { return "", err diff --git a/zboxcore/sdk/transaction_mobile.go b/zboxcore/sdk/transaction_mobile.go index d9d29e0eb..115dac8d4 100644 --- a/zboxcore/sdk/transaction_mobile.go +++ b/zboxcore/sdk/transaction_mobile.go @@ -57,11 +57,13 @@ func ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, v } wg.Add(1) - t, err := txn.ExecuteSmartContract(address, sn.Name, sn.InputArgs, value) + err = txn.ExecuteSmartContract(address, sn.Name, sn.InputArgs, value) if err != nil { return nil, err } + t := txn.GetTxn() + msg := fmt.Sprintf("Executing transaction '%s' with hash %s ", sn.Name, t.Hash) l.Logger.Info(msg) l.Logger.Info("estimated txn fee: ", t.TransactionFee) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 9a2fcfe10..0f81e31be 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -52,16 +52,9 @@ var ( _ TransactionScheme = (*TransactionWithAuth)(nil) ) -// Transaction represents entity that encapsulates the transaction related data and metadata. -type TransactionTest struct { -} - type TransactionCommon interface { - ExecuteSmartContracts(address, methodName string, val string, input string) (TransactionTest, error) - - ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) + ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error - // Send implements sending token to a given clientid Send(toClientID string, val string, desc string) error VestingAdd(ar VestingAddRequest, value string) error @@ -145,8 +138,6 @@ type TransactionScheme interface { VestingStop(sr *VestingStopRequest) error VestingUnlock(poolID string) error VestingDelete(poolID string) error - - // Miner SC } // priceRange represents a price range allowed by user to filter blobbers. @@ -427,6 +418,10 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac return t, err } +func (t *Transaction) GetTxn() *transaction.Transaction { + return t.txn +} + func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value string, opts ...FeeOption) error { sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} snBytes, err := json.Marshal(sn) @@ -482,21 +477,16 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContracts(address, methodName string, val string, input string) (TransactionTest, error) { - return TransactionTest{}, nil -} - -// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { +func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { err := t.createSmartContractTxn(address, methodName, input, val) if err != nil { - return nil, err + return err } go func() { t.setNonceAndSubmit() }() - return t.txn, nil + return nil } // Send to send a transaction to a given clientID diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 569ab1888..afbfb5b54 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -18,21 +18,20 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) return ta, err } -// ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *TransactionWithAuth) ExecuteSmartContracts(address string, methodName string, val string, input string) (TransactionTest, error) { - return TransactionTest{}, nil +func (ta *TransactionWithAuth) GetTxn() *transaction.Transaction { + return ta.t.txn } func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, - input interface{}, val string, feeOpts ...FeeOption) (*transaction.Transaction, error) { + input interface{}, val string, feeOpts ...FeeOption) error { err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) if err != nil { - return nil, err + return err } go func() { ta.submitTxn() }() - return ta.t.txn, nil + return nil } func (ta *TransactionWithAuth) Send(toClientID string, val string, desc string) error { From da7f552a773a0ce9ab7deda023c2f8a5d9075300 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 00:55:16 +0200 Subject: [PATCH 37/43] fix: fixed bugs --- zboxcore/sdk/transaction_mobile.go | 2 +- zcncore/transaction_mobile.go | 5 ++++- zcncore/transactionauth_mobile.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zboxcore/sdk/transaction_mobile.go b/zboxcore/sdk/transaction_mobile.go index 115dac8d4..18fa344ee 100644 --- a/zboxcore/sdk/transaction_mobile.go +++ b/zboxcore/sdk/transaction_mobile.go @@ -62,7 +62,7 @@ func ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, v return nil, err } - t := txn.GetTxn() + t := txn.GetDetails() msg := fmt.Sprintf("Executing transaction '%s' with hash %s ", sn.Name, t.Hash) l.Logger.Info(msg) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 0f81e31be..7a98baa47 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -126,6 +126,9 @@ type TransactionScheme interface { // GetTransactionNonce returns nonce GetTransactionNonce() int64 + // GetDetails returns transaction scheme details. + GetDetails() *transaction.Transaction + // Output of transaction. Output() []byte @@ -418,7 +421,7 @@ func NewTransaction(cb TransactionCallback, txnFee string, nonce int64) (Transac return t, err } -func (t *Transaction) GetTxn() *transaction.Transaction { +func (t *Transaction) GetDetails() *transaction.Transaction { return t.txn } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index afbfb5b54..b3fb21780 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -18,7 +18,7 @@ func newTransactionWithAuth(cb TransactionCallback, txnFee string, nonce int64) return ta, err } -func (ta *TransactionWithAuth) GetTxn() *transaction.Transaction { +func (ta *TransactionWithAuth) GetDetails() *transaction.Transaction { return ta.t.txn } From 017fad6f8cb759afa8488c61064575965b364fe9 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 01:06:09 +0200 Subject: [PATCH 38/43] fix: fixed bugs --- mobilesdk/zcn/smartcontract.go | 5 ++++- zboxcore/sdk/transaction_mobile.go | 2 +- zcncore/transaction_mobile.go | 6 +++--- zcncore/transactionauth_mobile.go | 6 +++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mobilesdk/zcn/smartcontract.go b/mobilesdk/zcn/smartcontract.go index 7df9025c8..9454e1cb6 100644 --- a/mobilesdk/zcn/smartcontract.go +++ b/mobilesdk/zcn/smartcontract.go @@ -8,6 +8,7 @@ import ( "fmt" "sync" + "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/zcncore" ) @@ -26,7 +27,9 @@ func ExecuteSmartContract(address, methodName, input, sasToken string) (string, wg.Add(1) - err = txn.ExecuteSmartContract(address, methodName, input, sasToken) + sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} + + err = txn.ExecuteSmartContract(address, sn, sasToken) if err != nil { return "", err diff --git a/zboxcore/sdk/transaction_mobile.go b/zboxcore/sdk/transaction_mobile.go index 18fa344ee..3ad34a385 100644 --- a/zboxcore/sdk/transaction_mobile.go +++ b/zboxcore/sdk/transaction_mobile.go @@ -57,7 +57,7 @@ func ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, v } wg.Add(1) - err = txn.ExecuteSmartContract(address, sn.Name, sn.InputArgs, value) + err = txn.ExecuteSmartContract(address, sn, value) if err != nil { return nil, err } diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 7a98baa47..d2f3c4037 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error + ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, opts ...FeeOption) error Send(toClientID string, val string, desc string) error @@ -480,8 +480,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContract(address, methodName string, input interface{}, val string, feeOpts ...FeeOption) error { - err := t.createSmartContractTxn(address, methodName, input, val) +func (t *Transaction) ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, opts ...FeeOption) error { + err := t.createSmartContractTxn(address, sn.Name, sn.InputArgs, val) if err != nil { return err } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index b3fb21780..2300eb297 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -22,15 +22,15 @@ func (ta *TransactionWithAuth) GetDetails() *transaction.Transaction { return ta.t.txn } -func (ta *TransactionWithAuth) ExecuteSmartContract(address, methodName string, - input interface{}, val string, feeOpts ...FeeOption) error { - err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) +func (ta *TransactionWithAuth) ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, feeOpts ...FeeOption) error { + err := ta.t.createSmartContractTxn(address, sn.Name, sn.InputArgs, val, feeOpts...) if err != nil { return err } go func() { ta.submitTxn() }() + return nil } From 3ae2ab9b7ef1d15671f709dd8bd9284255cd4f66 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 01:18:04 +0200 Subject: [PATCH 39/43] fix: fixed bugs --- core/transaction/entity.go | 6 ------ core/transaction/transaction.go | 6 ++++++ core/transaction/transaction_mobile.go | 6 ++++++ mobilesdk/zcn/smartcontract.go | 5 +---- zboxcore/sdk/transaction_mobile.go | 2 +- zcncore/transaction_mobile.go | 8 ++++---- zcncore/transactionauth_mobile.go | 4 ++-- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 2f9ea82ab..3d5232403 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -31,12 +31,6 @@ type TxnReceipt struct { Transaction *Transaction } -// SmartContractTxnData data structure to hold the smart contract transaction data -type SmartContractTxnData struct { - Name string `json:"name"` - InputArgs interface{} `json:"input"` -} - type StorageAllocation struct { ID string `json:"id"` DataShards int `json:"data_shards"` diff --git a/core/transaction/transaction.go b/core/transaction/transaction.go index 2040630cf..dabe0d495 100644 --- a/core/transaction/transaction.go +++ b/core/transaction/transaction.go @@ -3,6 +3,12 @@ package transaction +// SmartContractTxnData data structure to hold the smart contract transaction data +type SmartContractTxnData struct { + Name string `json:"name"` + InputArgs interface{} `json:"input"` +} + // Transaction entity that encapsulates the transaction related data and meta data type Transaction struct { Hash string `json:"hash,omitempty"` diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 3119429e5..24f5217c1 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -8,6 +8,12 @@ import ( "strconv" ) +// SmartContractTxnData data structure to hold the smart contract transaction data +type SmartContractTxnData struct { + Name string `json:"name"` + InputArgs string `json:"input"` +} + // Transaction represents entity that encapsulates the transaction related data and metadata. type Transaction struct { Hash string `json:"hash,omitempty"` diff --git a/mobilesdk/zcn/smartcontract.go b/mobilesdk/zcn/smartcontract.go index 9454e1cb6..7df9025c8 100644 --- a/mobilesdk/zcn/smartcontract.go +++ b/mobilesdk/zcn/smartcontract.go @@ -8,7 +8,6 @@ import ( "fmt" "sync" - "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/zcncore" ) @@ -27,9 +26,7 @@ func ExecuteSmartContract(address, methodName, input, sasToken string) (string, wg.Add(1) - sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} - - err = txn.ExecuteSmartContract(address, sn, sasToken) + err = txn.ExecuteSmartContract(address, methodName, input, sasToken) if err != nil { return "", err diff --git a/zboxcore/sdk/transaction_mobile.go b/zboxcore/sdk/transaction_mobile.go index 3ad34a385..18fa344ee 100644 --- a/zboxcore/sdk/transaction_mobile.go +++ b/zboxcore/sdk/transaction_mobile.go @@ -57,7 +57,7 @@ func ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, v } wg.Add(1) - err = txn.ExecuteSmartContract(address, sn, value) + err = txn.ExecuteSmartContract(address, sn.Name, sn.InputArgs, value) if err != nil { return nil, err } diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index d2f3c4037..4afb0b334 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, opts ...FeeOption) error + ExecuteSmartContract(address string, methodName string, input string, val string, opts ...FeeOption) error Send(toClientID string, val string, desc string) error @@ -425,7 +425,7 @@ func (t *Transaction) GetDetails() *transaction.Transaction { return t.txn } -func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value string, opts ...FeeOption) error { +func (t *Transaction) createSmartContractTxn(address, methodName string, input string, value string, opts ...FeeOption) error { sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} snBytes, err := json.Marshal(sn) if err != nil { @@ -480,8 +480,8 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, opts ...FeeOption) error { - err := t.createSmartContractTxn(address, sn.Name, sn.InputArgs, val) +func (t *Transaction) ExecuteSmartContract(address string, methodName string, input string, val string, opts ...FeeOption) error { + err := t.createSmartContractTxn(address, methodName, input, val) if err != nil { return err } diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 2300eb297..31930440d 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -22,8 +22,8 @@ func (ta *TransactionWithAuth) GetDetails() *transaction.Transaction { return ta.t.txn } -func (ta *TransactionWithAuth) ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, val string, feeOpts ...FeeOption) error { - err := ta.t.createSmartContractTxn(address, sn.Name, sn.InputArgs, val, feeOpts...) +func (ta *TransactionWithAuth) ExecuteSmartContract(address string, methodName string, input string, val string, feeOpts ...FeeOption) error { + err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) if err != nil { return err } From 064809bd5545f3fa24fce2e9aa9cc0be237b327d Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 01:20:48 +0200 Subject: [PATCH 40/43] fix: fixed bugs --- zcncore/transaction_mobile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 4afb0b334..9b3b2728d 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -425,7 +425,7 @@ func (t *Transaction) GetDetails() *transaction.Transaction { return t.txn } -func (t *Transaction) createSmartContractTxn(address, methodName string, input string, value string, opts ...FeeOption) error { +func (t *Transaction) createSmartContractTxn(address, methodName string, input interface{}, value string, opts ...FeeOption) error { sn := transaction.SmartContractTxnData{Name: methodName, InputArgs: input} snBytes, err := json.Marshal(sn) if err != nil { From 49e2b59c58f2b0c238efaef7b6791c00ebe1ad88 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 01:24:40 +0200 Subject: [PATCH 41/43] fix: fixed bugs --- core/transaction/entity.go | 6 ++++++ core/transaction/transaction.go | 6 ------ core/transaction/transaction_mobile.go | 6 ------ zboxcore/sdk/transaction_mobile.go | 8 +++++++- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 3d5232403..2f9ea82ab 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -31,6 +31,12 @@ type TxnReceipt struct { Transaction *Transaction } +// SmartContractTxnData data structure to hold the smart contract transaction data +type SmartContractTxnData struct { + Name string `json:"name"` + InputArgs interface{} `json:"input"` +} + type StorageAllocation struct { ID string `json:"id"` DataShards int `json:"data_shards"` diff --git a/core/transaction/transaction.go b/core/transaction/transaction.go index dabe0d495..2040630cf 100644 --- a/core/transaction/transaction.go +++ b/core/transaction/transaction.go @@ -3,12 +3,6 @@ package transaction -// SmartContractTxnData data structure to hold the smart contract transaction data -type SmartContractTxnData struct { - Name string `json:"name"` - InputArgs interface{} `json:"input"` -} - // Transaction entity that encapsulates the transaction related data and meta data type Transaction struct { Hash string `json:"hash,omitempty"` diff --git a/core/transaction/transaction_mobile.go b/core/transaction/transaction_mobile.go index 24f5217c1..3119429e5 100644 --- a/core/transaction/transaction_mobile.go +++ b/core/transaction/transaction_mobile.go @@ -8,12 +8,6 @@ import ( "strconv" ) -// SmartContractTxnData data structure to hold the smart contract transaction data -type SmartContractTxnData struct { - Name string `json:"name"` - InputArgs string `json:"input"` -} - // Transaction represents entity that encapsulates the transaction related data and metadata. type Transaction struct { Hash string `json:"hash,omitempty"` diff --git a/zboxcore/sdk/transaction_mobile.go b/zboxcore/sdk/transaction_mobile.go index 18fa344ee..3c28cb62b 100644 --- a/zboxcore/sdk/transaction_mobile.go +++ b/zboxcore/sdk/transaction_mobile.go @@ -57,7 +57,13 @@ func ExecuteSmartContract(address string, sn transaction.SmartContractTxnData, v } wg.Add(1) - err = txn.ExecuteSmartContract(address, sn.Name, sn.InputArgs, value) + + inputRaw, ok := sn.InputArgs.(string) + if !ok { + return nil, fmt.Errorf("failed to convert input args") + } + + err = txn.ExecuteSmartContract(address, sn.Name, inputRaw, value) if err != nil { return nil, err } From 9668750b9efd4f0d925f5b04cb60e54803229207 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 25 Sep 2024 01:33:04 +0200 Subject: [PATCH 42/43] fix: fixed bugs --- zcncore/transaction_mobile.go | 4 ++-- zcncore/transactionauth_mobile.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 9b3b2728d..0454d6fdd 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -53,7 +53,7 @@ var ( ) type TransactionCommon interface { - ExecuteSmartContract(address string, methodName string, input string, val string, opts ...FeeOption) error + ExecuteSmartContract(address string, methodName string, input string, val string) error Send(toClientID string, val string, desc string) error @@ -480,7 +480,7 @@ func (t *Transaction) createFaucetSCWallet(walletStr string, methodName string, } // ExecuteSmartContract prepare and send a smart contract transaction to the blockchain -func (t *Transaction) ExecuteSmartContract(address string, methodName string, input string, val string, opts ...FeeOption) error { +func (t *Transaction) ExecuteSmartContract(address string, methodName string, input string, val string) error { err := t.createSmartContractTxn(address, methodName, input, val) if err != nil { return err diff --git a/zcncore/transactionauth_mobile.go b/zcncore/transactionauth_mobile.go index 31930440d..046ed314c 100644 --- a/zcncore/transactionauth_mobile.go +++ b/zcncore/transactionauth_mobile.go @@ -22,8 +22,8 @@ func (ta *TransactionWithAuth) GetDetails() *transaction.Transaction { return ta.t.txn } -func (ta *TransactionWithAuth) ExecuteSmartContract(address string, methodName string, input string, val string, feeOpts ...FeeOption) error { - err := ta.t.createSmartContractTxn(address, methodName, input, val, feeOpts...) +func (ta *TransactionWithAuth) ExecuteSmartContract(address string, methodName string, input string, val string) error { + err := ta.t.createSmartContractTxn(address, methodName, input, val) if err != nil { return err } From 2480cab2daedc644dbde5a245ad93d935131639f Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Fri, 27 Sep 2024 08:30:20 +0200 Subject: [PATCH 43/43] fix: fixed bugs --- wasmsdk/auth_txn.go | 6 +++--- wasmsdk/proxy.go | 4 ++-- zcncore/zauth.go | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/wasmsdk/auth_txn.go b/wasmsdk/auth_txn.go index 184b52018..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, roles []string) (string, error) { - return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID) + return zcncore.CallZvaultNewWalletString(serverAddr, token, clientID, roles) } func zvaultStoreKey(serverAddr, token, privateKey string) (string, error) { diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index ab21d090a..1927d8d04 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -82,7 +82,7 @@ func main() { return "", fmt.Errorf("failed to sign with split key: %v", err) } - data, err := json.Marshal(zauth.AuthMessage{ + data, err := json.Marshal(zcncore.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID, @@ -379,7 +379,7 @@ func main() { return "", fmt.Errorf("failed to sign with split key: %v", err) } - data, err := json.Marshal(zauth.AuthMessage{ + data, err := json.Marshal(zcncore.AuthMessage{ Hash: hash, Signature: sig, ClientID: client.GetClient().ClientID, diff --git a/zcncore/zauth.go b/zcncore/zauth.go index b10cd7bc7..fdb240a80 100644 --- a/zcncore/zauth.go +++ b/zcncore/zauth.go @@ -164,14 +164,20 @@ func CallZvaultNewWalletString(serverAddr, token, clientID string, roles []strin endpoint = endpoint + "/" + clientID } - data, err := json.Marshal(newWalletRequest{ - Roles: roles, - }) - if err != nil { - return "", errors.Wrap(err, "failed to serialize request") + var body io.Reader + + if roles != nil { + data, err := json.Marshal(newWalletRequest{ + Roles: roles, + }) + if err != nil { + return "", errors.Wrap(err, "failed to serialize request") + } + + body = bytes.NewReader(data) } - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(data)) + req, err := http.NewRequest("POST", endpoint, body) if err != nil { return "", errors.Wrap(err, "failed to create HTTP request") }