diff --git a/.env.local b/.env.local index 08ca6d2..6378881 100755 --- a/.env.local +++ b/.env.local @@ -5,6 +5,3 @@ MY_ADDR="cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB" # testnet RPC_ADDRS="ws://localhost:9944" - -# testnet -BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.network" diff --git a/.env.testnet b/.env.testnet index 0b21e82..2d76daa 100755 --- a/.env.testnet +++ b/.env.testnet @@ -6,6 +6,3 @@ MY_ADDR="cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB" # root # testnet RPC_ADDRS="wss://testnet-rpc.cess.network/ws/" - -# testnet -BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.network" diff --git a/chain/audit.go b/chain/audit.go index cbd0f0b..320f381 100755 --- a/chain/audit.go +++ b/chain/audit.go @@ -194,11 +194,9 @@ func (c *ChainClient) QueryCountedServiceFailed(accountID []byte, block int32) ( // - string: block hash // - error: error message func (c *ChainClient) SubmitIdleProof(idleProof []types.U8) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -227,6 +225,14 @@ func (c *ChainClient) SubmitIdleProof(idleProof []types.U8) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_idle_proof, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_idle_proof, err) @@ -254,17 +260,6 @@ func (c *ChainClient) SubmitIdleProof(idleProof []types.U8) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_idle_proof, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -274,7 +269,6 @@ func (c *ChainClient) SubmitIdleProof(idleProof []types.U8) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_idle_proof, err) @@ -315,11 +309,9 @@ func (c *ChainClient) SubmitIdleProof(idleProof []types.U8) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) SubmitServiceProof(serviceProof []types.U8) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -344,6 +336,14 @@ func (c *ChainClient) SubmitServiceProof(serviceProof []types.U8) (string, error return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_service_proof, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_service_proof, err) @@ -371,17 +371,6 @@ func (c *ChainClient) SubmitServiceProof(serviceProof []types.U8) (string, error return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_service_proof, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -391,7 +380,6 @@ func (c *ChainClient) SubmitServiceProof(serviceProof []types.U8) (string, error if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_service_proof, err) @@ -438,11 +426,9 @@ func (c *ChainClient) SubmitServiceProof(serviceProof []types.U8) (string, error // - string: block hash // - error: error message func (c *ChainClient) SubmitVerifyIdleResult(totalProofHash []types.U8, front, rear types.U64, accumulator Accumulator, result types.Bool, sig types.Bytes, teePuk WorkerPublicKey) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -467,6 +453,14 @@ func (c *ChainClient) SubmitVerifyIdleResult(totalProofHash []types.U8, front, r return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_idle_result, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_idle_result, err) @@ -494,17 +488,6 @@ func (c *ChainClient) SubmitVerifyIdleResult(totalProofHash []types.U8, front, r return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_idle_result, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -514,7 +497,6 @@ func (c *ChainClient) SubmitVerifyIdleResult(totalProofHash []types.U8, front, r if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_idle_result, err) @@ -558,11 +540,9 @@ func (c *ChainClient) SubmitVerifyIdleResult(totalProofHash []types.U8, front, r // - string: block hash // - error: error message func (c *ChainClient) SubmitVerifyServiceResult(result types.Bool, sign types.Bytes, bloomFilter BloomFilter, teePuk WorkerPublicKey) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -587,6 +567,14 @@ func (c *ChainClient) SubmitVerifyServiceResult(result types.Bool, sign types.By return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_service_result, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_service_result, err) @@ -614,17 +602,6 @@ func (c *ChainClient) SubmitVerifyServiceResult(result types.Bool, sign types.By return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_service_result, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -634,7 +611,6 @@ func (c *ChainClient) SubmitVerifyServiceResult(result types.Bool, sign types.By if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Audit_submit_verify_service_result, err) diff --git a/chain/balances.go b/chain/balances.go index b8d204d..9aa8dce 100644 --- a/chain/balances.go +++ b/chain/balances.go @@ -153,11 +153,9 @@ func (c *ChainClient) QueryInactiveIssuance(block int32) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) TransferToken(dest string, amount string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -197,6 +195,14 @@ func (c *ChainClient) TransferToken(dest string, amount string) (string, error) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Balances_transferKeepAlive, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err = c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Balances_transferKeepAlive, err) @@ -224,17 +230,6 @@ func (c *ChainClient) TransferToken(dest string, amount string) (string, error) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Balances_transferKeepAlive, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { diff --git a/chain/chain.go b/chain/chain.go index 8957443..1eeadcf 100755 --- a/chain/chain.go +++ b/chain/chain.go @@ -30,7 +30,6 @@ import ( type ChainClient struct { lock *sync.Mutex chainStLock *sync.Mutex - txTicker *time.Ticker api *gsrpc.SubstrateAPI metadata *types.Metadata runtimeVersion *types.RuntimeVersion @@ -39,12 +38,13 @@ type ChainClient struct { keyring signature.KeyringPair rpcAddr []string currentRpcAddr string - packingTime time.Duration tokenSymbol string networkEnv string signatureAcc string name string balance uint64 + packingTime time.Duration + tradeCh chan bool rpcState bool } @@ -65,11 +65,12 @@ func NewChainClientUnconnectedRpc(ctx context.Context, name string, rpcs []strin var chainClient = &ChainClient{ lock: new(sync.Mutex), chainStLock: new(sync.Mutex), - txTicker: time.NewTicker(BlockInterval), + tradeCh: make(chan bool, 1), rpcAddr: rpcs, packingTime: t, name: name, } + chainClient.tradeCh <- true if mnemonic != "" { chainClient.keyring, err = signature.KeyringPairFromSecret(mnemonic, 0) if err != nil { @@ -100,12 +101,13 @@ func NewChainClient(ctx context.Context, name string, rpcs []string, mnemonic st chainClient = &ChainClient{ lock: new(sync.Mutex), chainStLock: new(sync.Mutex), - txTicker: time.NewTicker(BlockInterval), + tradeCh: make(chan bool, 1), rpcAddr: rpcs, packingTime: t, name: name, } ) + chainClient.tradeCh <- true log.SetOutput(io.Discard) for i := 0; i < len(rpcs); i++ { diff --git a/chain/deoss.go b/chain/deoss.go index 746718e..fd5567a 100755 --- a/chain/deoss.go +++ b/chain/deoss.go @@ -274,11 +274,9 @@ func (c *ChainClient) QueryAuthorityList(accountID []byte, block int32) ([]types // Node: // - accountID should be oss account func (c *ChainClient) Authorize(accountID []byte) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -308,6 +306,14 @@ func (c *ChainClient) Authorize(accountID []byte) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_authorize, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Oss_authorize, err) @@ -335,17 +341,6 @@ func (c *ChainClient) Authorize(accountID []byte) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_authorize, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -355,7 +350,6 @@ func (c *ChainClient) Authorize(accountID []byte) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Oss_authorize, err) @@ -396,11 +390,9 @@ func (c *ChainClient) Authorize(accountID []byte) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) CancelAuthorize(accountID []byte) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -425,6 +417,14 @@ func (c *ChainClient) CancelAuthorize(accountID []byte) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_cancel_authorize, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Oss_cancel_authorize, err) @@ -452,17 +452,6 @@ func (c *ChainClient) CancelAuthorize(accountID []byte) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_cancel_authorize, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -472,7 +461,6 @@ func (c *ChainClient) CancelAuthorize(accountID []byte) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Oss_cancel_authorize, err) @@ -514,11 +502,9 @@ func (c *ChainClient) CancelAuthorize(accountID []byte) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) RegisterOss(peerId []byte, domain string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -560,6 +546,14 @@ func (c *ChainClient) RegisterOss(peerId []byte, domain string) (string, error) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_register, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Oss_register, err) @@ -593,17 +587,6 @@ func (c *ChainClient) RegisterOss(peerId []byte, domain string) (string, error) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_register, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -613,7 +596,6 @@ func (c *ChainClient) RegisterOss(peerId []byte, domain string) (string, error) if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Oss_register, err) @@ -655,11 +637,9 @@ func (c *ChainClient) RegisterOss(peerId []byte, domain string) (string, error) // - string: block hash // - error: error message func (c *ChainClient) UpdateOss(peerId string, domain string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -701,6 +681,14 @@ func (c *ChainClient) UpdateOss(peerId string, domain string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_update, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Oss_update, err) @@ -728,17 +716,6 @@ func (c *ChainClient) UpdateOss(peerId string, domain string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_update, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -748,7 +725,6 @@ func (c *ChainClient) UpdateOss(peerId string, domain string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Oss_update, err) @@ -786,11 +762,9 @@ func (c *ChainClient) UpdateOss(peerId string, domain string) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) DestroyOss() (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -815,6 +789,14 @@ func (c *ChainClient) DestroyOss() (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_destroy, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Oss_destroy, err) @@ -843,17 +825,6 @@ func (c *ChainClient) DestroyOss() (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Oss_destroy, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -863,7 +834,6 @@ func (c *ChainClient) DestroyOss() (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Oss_destroy, err) diff --git a/chain/evm.go b/chain/evm.go index afd1998..b9db776 100644 --- a/chain/evm.go +++ b/chain/evm.go @@ -19,11 +19,9 @@ import ( ) func (c *ChainClient) SendEvmCall(source types.H160, target types.H160, input types.Bytes, value types.U256, gasLimit types.U64, maxFeePerGas types.U256, accessList []AccessInfo) (string, error) { - if !c.GetRpcState() { - return "", fmt.Errorf("chainSDK.UploadDeclaration(): GetRpcState(): %v", ERR_RPC_CONNECTION) - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -54,6 +52,14 @@ func (c *ChainClient) SendEvmCall(source types.H160, target types.H160, input ty return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Evm_call, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Evm_call, err) @@ -86,17 +92,6 @@ func (c *ChainClient) SendEvmCall(source types.H160, target types.H160, input ty return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Evm_call, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { if strings.Contains(err.Error(), ERR_PriorityIsTooLow) { diff --git a/chain/file_bank.go b/chain/file_bank.go index 31978c0..8a60205 100755 --- a/chain/file_bank.go +++ b/chain/file_bank.go @@ -715,11 +715,9 @@ func (c *ChainClient) PlaceStorageOrder(fid, file_name, bucket_name, territory_n // - string: block hash // - error: error message func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user UserBrief, filesize uint64) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -754,6 +752,14 @@ func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_upload_declaration, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_upload_declaration, err) @@ -786,17 +792,6 @@ func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_upload_declaration, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -806,7 +801,6 @@ func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_upload_declaration, err) @@ -852,11 +846,9 @@ func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user // - cannot create a bucket that already exists // - if you are not the owner, the owner account must be authorised to you func (c *ChainClient) CreateBucket(owner []byte, bucketName string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -886,6 +878,14 @@ func (c *ChainClient) CreateBucket(owner []byte, bucketName string) (string, err return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_create_bucket, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_create_bucket, err) @@ -913,17 +913,6 @@ func (c *ChainClient) CreateBucket(owner []byte, bucketName string) (string, err return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_create_bucket, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -963,11 +952,9 @@ func (c *ChainClient) CreateBucket(owner []byte, bucketName string) (string, err // Note: // - if you are not the owner, the owner account must be authorised to you func (c *ChainClient) DeleteBucket(owner []byte, bucketName string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -997,6 +984,14 @@ func (c *ChainClient) DeleteBucket(owner []byte, bucketName string) (string, err return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_bucket, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_bucket, err) @@ -1024,17 +1019,6 @@ func (c *ChainClient) DeleteBucket(owner []byte, bucketName string) (string, err return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_bucket, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1074,11 +1058,9 @@ func (c *ChainClient) DeleteBucket(owner []byte, bucketName string) (string, err // Note: // - if you are not the owner, the owner account must be authorised to you func (c *ChainClient) DeleteFile(owner []byte, fid string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1117,6 +1099,14 @@ func (c *ChainClient) DeleteFile(owner []byte, fid string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_file, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_file, err) @@ -1144,17 +1134,6 @@ func (c *ChainClient) DeleteFile(owner []byte, fid string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_file, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1164,7 +1143,6 @@ func (c *ChainClient) DeleteFile(owner []byte, fid string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_delete_file, err) @@ -1210,11 +1188,9 @@ func (c *ChainClient) DeleteFile(owner []byte, fid string) (string, error) { // Note: // - for storage miner use only func (c *ChainClient) TransferReport(index uint8, fid string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1249,6 +1225,14 @@ func (c *ChainClient) TransferReport(index uint8, fid string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_transfer_report, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_transfer_report, err) @@ -1276,17 +1260,6 @@ func (c *ChainClient) TransferReport(index uint8, fid string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_transfer_report, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1296,7 +1269,6 @@ func (c *ChainClient) TransferReport(index uint8, fid string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_transfer_report, err) @@ -1341,11 +1313,9 @@ func (c *ChainClient) TransferReport(index uint8, fid string) (string, error) { // Note: // - for storage miner use only func (c *ChainClient) GenerateRestoralOrder(fid, fragmentHash string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1389,6 +1359,14 @@ func (c *ChainClient) GenerateRestoralOrder(fid, fragmentHash string) (string, e return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_generate_restoral_order, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_generate_restoral_order, err) @@ -1416,17 +1394,6 @@ func (c *ChainClient) GenerateRestoralOrder(fid, fragmentHash string) (string, e return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_generate_restoral_order, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1465,11 +1432,9 @@ func (c *ChainClient) GenerateRestoralOrder(fid, fragmentHash string) (string, e // Note: // - for storage miner use only func (c *ChainClient) ClaimRestoralOrder(fragmentHash string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1503,6 +1468,14 @@ func (c *ChainClient) ClaimRestoralOrder(fragmentHash string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_order, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_order, err) @@ -1530,17 +1503,6 @@ func (c *ChainClient) ClaimRestoralOrder(fragmentHash string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_order, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1550,7 +1512,6 @@ func (c *ChainClient) ClaimRestoralOrder(fragmentHash string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_order, err) @@ -1596,11 +1557,9 @@ func (c *ChainClient) ClaimRestoralOrder(fragmentHash string) (string, error) { // Note: // - for storage miner use only func (c *ChainClient) ClaimRestoralNoExistOrder(puk []byte, fid, fragmentHash string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1649,6 +1608,14 @@ func (c *ChainClient) ClaimRestoralNoExistOrder(puk []byte, fid, fragmentHash st return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_noexist_order, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_noexist_order, err) @@ -1675,17 +1642,6 @@ func (c *ChainClient) ClaimRestoralNoExistOrder(puk []byte, fid, fragmentHash st return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_noexist_order, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1695,7 +1651,6 @@ func (c *ChainClient) ClaimRestoralNoExistOrder(puk []byte, fid, fragmentHash st if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_claim_restoral_noexist_order, err) @@ -1739,11 +1694,9 @@ func (c *ChainClient) ClaimRestoralNoExistOrder(puk []byte, fid, fragmentHash st // Note: // - for storage miner use only func (c *ChainClient) RestoralOrderComplete(fragmentHash string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1776,6 +1729,14 @@ func (c *ChainClient) RestoralOrderComplete(fragmentHash string) (string, error) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_restoral_order_complete, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_restoral_order_complete, err) @@ -1805,17 +1766,6 @@ func (c *ChainClient) RestoralOrderComplete(fragmentHash string) (string, error) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_restoral_order_complete, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1871,11 +1821,9 @@ func (c *ChainClient) RestoralOrderComplete(fragmentHash string) (string, error) // Note: // - for storage miner use only func (c *ChainClient) CertIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAcc, teeSign types.Bytes, teePuk WorkerPublicKey) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1898,6 +1846,14 @@ func (c *ChainClient) CertIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAc return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_cert_idle_space, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_cert_idle_space, err) @@ -1927,17 +1883,6 @@ func (c *ChainClient) CertIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAc return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_cert_idle_space, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1947,7 +1892,6 @@ func (c *ChainClient) CertIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAc if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_cert_idle_space, err) @@ -1994,11 +1938,9 @@ func (c *ChainClient) CertIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAc // Note: // - for storage miner use only func (c *ChainClient) ReplaceIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWithAcc, teeSign types.Bytes, teePuk WorkerPublicKey) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -2021,6 +1963,14 @@ func (c *ChainClient) ReplaceIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWit return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_replace_idle_space, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_replace_idle_space, err) @@ -2050,17 +2000,6 @@ func (c *ChainClient) ReplaceIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWit return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_replace_idle_space, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -2070,7 +2009,6 @@ func (c *ChainClient) ReplaceIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWit if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_replace_idle_space, err) @@ -2115,11 +2053,9 @@ func (c *ChainClient) ReplaceIdleSpace(spaceProofInfo SpaceProofInfo, teeSignWit // Note: // - for storage miner use only func (c *ChainClient) CalculateReport(teeSig types.Bytes, tagSigInfo TagSigInfo) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -2144,6 +2080,14 @@ func (c *ChainClient) CalculateReport(teeSig types.Bytes, tagSigInfo TagSigInfo) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_calculate_report, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_calculate_report, err) @@ -2171,17 +2115,6 @@ func (c *ChainClient) CalculateReport(teeSig types.Bytes, tagSigInfo TagSigInfo) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_calculate_report, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -2191,7 +2124,6 @@ func (c *ChainClient) CalculateReport(teeSig types.Bytes, tagSigInfo TagSigInfo) if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_calculate_report, err) @@ -2234,11 +2166,9 @@ func (c *ChainClient) CalculateReport(teeSig types.Bytes, tagSigInfo TagSigInfo) // - string: block hash // - error: error message func (c *ChainClient) TerritoryFileDelivery(user []byte, fid string, target_territory string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -2268,6 +2198,14 @@ func (c *ChainClient) TerritoryFileDelivery(user []byte, fid string, target_terr return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_territory_file_delivery, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_FileBank_territory_file_delivery, err) @@ -2295,17 +2233,6 @@ func (c *ChainClient) TerritoryFileDelivery(user []byte, fid string, target_terr return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_FileBank_territory_file_delivery, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { diff --git a/chain/sminer.go b/chain/sminer.go index 9498876..4352cf4 100755 --- a/chain/sminer.go +++ b/chain/sminer.go @@ -721,11 +721,9 @@ func (c *ChainClient) QueryCompleteMinerSnapShot(puk []byte, block int32) (Miner // - The number of staking to be added is calculated in the smallest unit, // if you want to add 1CESS staking, you need to fill in "1000000000000000000" func (c *ChainClient) IncreaseCollateral(accountID []byte, token string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -760,6 +758,14 @@ func (c *ChainClient) IncreaseCollateral(accountID []byte, token string) (string return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_collateral, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err = c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_collateral, err) @@ -787,17 +793,6 @@ func (c *ChainClient) IncreaseCollateral(accountID []byte, token string) (string return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_collateral, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -807,7 +802,6 @@ func (c *ChainClient) IncreaseCollateral(accountID []byte, token string) (string if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_collateral, err) @@ -852,11 +846,9 @@ func (c *ChainClient) IncreaseCollateral(accountID []byte, token string) (string // - the size of the declared space cannot be reduced // - when the staking does not meet the declared space size, you will be frozen func (c *ChainClient) IncreaseDeclarationSpace(tibCount uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -881,6 +873,14 @@ func (c *ChainClient) IncreaseDeclarationSpace(tibCount uint32) (string, error) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_declaration_space, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_declaration_space, err) @@ -908,17 +908,6 @@ func (c *ChainClient) IncreaseDeclarationSpace(tibCount uint32) (string, error) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_declaration_space, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -928,7 +917,6 @@ func (c *ChainClient) IncreaseDeclarationSpace(tibCount uint32) (string, error) if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_increase_declaration_space, err) @@ -972,11 +960,9 @@ func (c *ChainClient) IncreaseDeclarationSpace(tibCount uint32) (string, error) // - after pre-exit, you need to wait for one day before it will automatically exit // - cannot register as a storage miner again after pre-exit func (c *ChainClient) MinerExitPrep() (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1008,6 +994,14 @@ func (c *ChainClient) MinerExitPrep() (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_exit, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_exit, err) @@ -1036,17 +1030,6 @@ func (c *ChainClient) MinerExitPrep() (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_exit, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1056,7 +1039,6 @@ func (c *ChainClient) MinerExitPrep() (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_exit, err) @@ -1100,11 +1082,9 @@ func (c *ChainClient) MinerExitPrep() (string, error) { // - must be an exited miner to withdraw // - wait a day to withdraw after pre-exit func (c *ChainClient) MinerWithdraw() (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1129,6 +1109,14 @@ func (c *ChainClient) MinerWithdraw() (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_withdraw, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_withdraw, err) @@ -1156,17 +1144,6 @@ func (c *ChainClient) MinerWithdraw() (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_withdraw, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1176,7 +1153,6 @@ func (c *ChainClient) MinerWithdraw() (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_miner_withdraw, err) @@ -1221,11 +1197,9 @@ func (c *ChainClient) MinerWithdraw() (string, error) { // - for storage miner only // - pass at least one idle and service challenge at the same time to get the reward func (c *ChainClient) ReceiveReward() (string, string, error) { - if !c.GetRpcState() { - return "", "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1251,6 +1225,14 @@ func (c *ChainClient) ReceiveReward() (string, string, error) { return blockhash, earningsAcc, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_receive_reward, ERR_RPC_CONNECTION.Error()) + return blockhash, earningsAcc, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_receive_reward, err) @@ -1278,17 +1260,6 @@ func (c *ChainClient) ReceiveReward() (string, string, error) { return blockhash, earningsAcc, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_receive_reward, ERR_RPC_CONNECTION.Error()) - return blockhash, "", err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1346,11 +1317,9 @@ func (c *ChainClient) ReceiveReward() (string, string, error) { // Note: // - storage miners must complete the first stage to register for the second stage func (c *ChainClient) RegisterPoisKey(poisKey PoISKeyInfo, teeSignWithAcc, teeSign types.Bytes, teePuk WorkerPublicKey) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1375,6 +1344,14 @@ func (c *ChainClient) RegisterPoisKey(poisKey PoISKeyInfo, teeSignWithAcc, teeSi return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_register_pois_key, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_register_pois_key, err) @@ -1408,17 +1385,6 @@ func (c *ChainClient) RegisterPoisKey(poisKey PoISKeyInfo, teeSignWithAcc, teeSi return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_register_pois_key, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1428,7 +1394,6 @@ func (c *ChainClient) RegisterPoisKey(poisKey PoISKeyInfo, teeSignWithAcc, teeSi if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_register_pois_key, err) @@ -1474,11 +1439,9 @@ func (c *ChainClient) RegisterPoisKey(poisKey PoISKeyInfo, teeSignWithAcc, teeSi // - string: block hash // - error: error message func (c *ChainClient) RegnstkSminer(earnings string, peerId []byte, staking uint64, tibCount uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1524,6 +1487,14 @@ func (c *ChainClient) RegnstkSminer(earnings string, peerId []byte, staking uint return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err = c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk, err) @@ -1557,17 +1528,6 @@ func (c *ChainClient) RegnstkSminer(earnings string, peerId []byte, staking uint return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1577,7 +1537,6 @@ func (c *ChainClient) RegnstkSminer(earnings string, peerId []byte, staking uint if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk, err) @@ -1624,11 +1583,9 @@ func (c *ChainClient) RegnstkSminer(earnings string, peerId []byte, staking uint // - string: block hash // - error: error message func (c *ChainClient) RegnstkAssignStaking(earnings string, peerId []byte, stakingAcc string, tibCount uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1685,6 +1642,14 @@ func (c *ChainClient) RegnstkAssignStaking(earnings string, peerId []byte, staki return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk_assign_staking, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk_assign_staking, err) @@ -1718,17 +1683,6 @@ func (c *ChainClient) RegnstkAssignStaking(earnings string, peerId []byte, staki return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk_assign_staking, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1738,7 +1692,6 @@ func (c *ChainClient) RegnstkAssignStaking(earnings string, peerId []byte, staki if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_regnstk_assign_staking, err) @@ -1780,11 +1733,9 @@ func (c *ChainClient) RegnstkAssignStaking(earnings string, peerId []byte, staki // - string: block hash // - error: error message func (c *ChainClient) UpdateBeneficiary(earnings string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1819,6 +1770,14 @@ func (c *ChainClient) UpdateBeneficiary(earnings string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_update_beneficiary, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_update_beneficiary, err) @@ -1846,17 +1805,6 @@ func (c *ChainClient) UpdateBeneficiary(earnings string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_update_beneficiary, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1866,7 +1814,6 @@ func (c *ChainClient) UpdateBeneficiary(earnings string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_update_beneficiary, err) @@ -1908,11 +1855,9 @@ func (c *ChainClient) UpdateBeneficiary(earnings string) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) UpdateSminerPeerId(peerid PeerId) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1937,6 +1882,14 @@ func (c *ChainClient) UpdateSminerPeerId(peerid PeerId) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_update_peer_id, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_update_peer_id, err) @@ -1964,17 +1917,6 @@ func (c *ChainClient) UpdateSminerPeerId(peerid PeerId) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_Sminer_update_peer_id, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1984,7 +1926,6 @@ func (c *ChainClient) UpdateSminerPeerId(peerid PeerId) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_Sminer_update_peer_id, err) diff --git a/chain/storage_handler.go b/chain/storage_handler.go index a6216f2..966dc66 100755 --- a/chain/storage_handler.go +++ b/chain/storage_handler.go @@ -387,11 +387,9 @@ func (c *ChainClient) QueryConsignment(token types.H256, block int32) (Consignme // - string: block hash // - error: error message func (c *ChainClient) MintTerritory(gib_count uint32, territory_name string, days uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -424,6 +422,14 @@ func (c *ChainClient) MintTerritory(gib_count uint32, territory_name string, day return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_mint_territory, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_mint_territory, err) @@ -451,17 +457,6 @@ func (c *ChainClient) MintTerritory(gib_count uint32, territory_name string, day return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_mint_territory, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -471,7 +466,6 @@ func (c *ChainClient) MintTerritory(gib_count uint32, territory_name string, day if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_mint_territory, err) @@ -513,11 +507,9 @@ func (c *ChainClient) MintTerritory(gib_count uint32, territory_name string, day // - string: block hash // - error: error message func (c *ChainClient) ExpandingTerritory(territory_name string, gib_count uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -546,6 +538,14 @@ func (c *ChainClient) ExpandingTerritory(territory_name string, gib_count uint32 return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_expanding_territory, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_expanding_territory, err) @@ -573,17 +573,6 @@ func (c *ChainClient) ExpandingTerritory(territory_name string, gib_count uint32 return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_expanding_territory, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -593,7 +582,6 @@ func (c *ChainClient) ExpandingTerritory(territory_name string, gib_count uint32 if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_expanding_territory, err) @@ -635,11 +623,9 @@ func (c *ChainClient) ExpandingTerritory(territory_name string, gib_count uint32 // - string: block hash // - error: error message func (c *ChainClient) RenewalTerritory(territory_name string, days_count uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -668,6 +654,14 @@ func (c *ChainClient) RenewalTerritory(territory_name string, days_count uint32) return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_renewal_territory, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_renewal_territory, err) @@ -695,17 +689,6 @@ func (c *ChainClient) RenewalTerritory(territory_name string, days_count uint32) return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_renewal_territory, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -715,7 +698,6 @@ func (c *ChainClient) RenewalTerritory(territory_name string, days_count uint32) if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_renewal_territory, err) @@ -757,11 +739,9 @@ func (c *ChainClient) RenewalTerritory(territory_name string, days_count uint32) // - string: block hash // - error: error message func (c *ChainClient) ReactivateTerritory(territory_name string, days_count uint32) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -790,6 +770,14 @@ func (c *ChainClient) ReactivateTerritory(territory_name string, days_count uint return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_reactivate_territory, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_reactivate_territory, err) @@ -817,17 +805,6 @@ func (c *ChainClient) ReactivateTerritory(territory_name string, days_count uint return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_reactivate_territory, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -837,7 +814,6 @@ func (c *ChainClient) ReactivateTerritory(territory_name string, days_count uint if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_reactivate_territory, err) @@ -882,11 +858,9 @@ func (c *ChainClient) ReactivateTerritory(territory_name string, days_count uint // - The territory must be in an active state // - Remaining lease term greater than 1 day func (c *ChainClient) TerritoryConsignment(territory_name string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -911,6 +885,14 @@ func (c *ChainClient) TerritoryConsignment(territory_name string) (string, error return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_territory_consignment, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_territory_consignment, err) @@ -938,17 +920,6 @@ func (c *ChainClient) TerritoryConsignment(territory_name string) (string, error return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_territory_consignment, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -958,7 +929,6 @@ func (c *ChainClient) TerritoryConsignment(territory_name string) (string, error if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_territory_consignment, err) @@ -999,11 +969,9 @@ func (c *ChainClient) TerritoryConsignment(territory_name string) (string, error // - string: block hash // - error: error message func (c *ChainClient) CancelConsignment(territory_name string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1028,6 +996,14 @@ func (c *ChainClient) CancelConsignment(territory_name string) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_consignment, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_consignment, err) @@ -1055,17 +1031,6 @@ func (c *ChainClient) CancelConsignment(territory_name string) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_consignment, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1075,7 +1040,6 @@ func (c *ChainClient) CancelConsignment(territory_name string) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_consignment, err) @@ -1117,11 +1081,9 @@ func (c *ChainClient) CancelConsignment(territory_name string) (string, error) { // - string: block hash // - error: error message func (c *ChainClient) BuyConsignment(token types.H256, territory_name string) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1150,6 +1112,14 @@ func (c *ChainClient) BuyConsignment(token types.H256, territory_name string) (s return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_buy_consignment, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_buy_consignment, err) @@ -1177,17 +1147,6 @@ func (c *ChainClient) BuyConsignment(token types.H256, territory_name string) (s return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_buy_consignment, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1197,7 +1156,6 @@ func (c *ChainClient) BuyConsignment(token types.H256, territory_name string) (s if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_buy_consignment, err) @@ -1238,11 +1196,9 @@ func (c *ChainClient) BuyConsignment(token types.H256, territory_name string) (s // - string: block hash // - error: error message func (c *ChainClient) CancelPurchaseAction(token types.H256) (string, error) { - if !c.GetRpcState() { - return "", ERR_RPC_CONNECTION - } - + <-c.tradeCh defer func() { + c.tradeCh <- true if err := recover(); err != nil { log.Println(utils.RecoverError(err)) } @@ -1267,6 +1223,14 @@ func (c *ChainClient) CancelPurchaseAction(token types.H256) (string, error) { return blockhash, err } + if !c.GetRpcState() { + err = c.ReconnectRpc() + if err != nil { + err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_purchase_action, ERR_RPC_CONNECTION.Error()) + return blockhash, err + } + } + ok, err := c.api.RPC.State.GetStorageLatest(key, &accountInfo) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_purchase_action, err) @@ -1294,17 +1258,6 @@ func (c *ChainClient) CancelPurchaseAction(token types.H256) (string, error) { return blockhash, err } - <-c.txTicker.C - - if !c.GetRpcState() { - err = c.ReconnectRpc() - if err != nil { - err = fmt.Errorf("rpc err: [%s] [tx] [%s] %s", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_purchase_action, ERR_RPC_CONNECTION.Error()) - return blockhash, err - } - <-c.txTicker.C - } - // Do the transfer and track the actual status sub, err := c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { @@ -1314,7 +1267,6 @@ func (c *ChainClient) CancelPurchaseAction(token types.H256) (string, error) { if err != nil { return blockhash, errors.Wrap(err, "[Sign]") } - <-c.txTicker.C sub, err = c.api.RPC.Author.SubmitAndWatchExtrinsic(ext) if err != nil { err = fmt.Errorf("rpc err: [%s] [tx] [%s] SubmitAndWatchExtrinsic: %v", c.GetCurrentRpcAddr(), ExtName_StorageHandler_cancel_purchase_action, err) diff --git a/go.mod b/go.mod index 0da28fa..73add0e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1 github.com/ethereum/go-ethereum v1.10.20 github.com/go-ping/ping v1.1.0 - github.com/google/uuid v1.5.0 + github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 github.com/klauspost/reedsolomon v1.12.0 github.com/mr-tron/base58 v1.2.0 @@ -20,8 +20,8 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.9.0 github.com/vedhavyas/go-subkey v1.0.4 - golang.org/x/crypto v0.19.0 - golang.org/x/exp v0.0.0-20240213143201-ec583247a57a + golang.org/x/crypto v0.25.0 + golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 ) require ( @@ -33,13 +33,13 @@ require ( github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/base58 v1.0.4 // indirect github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-stack/stack v1.8.1 // indirect - github.com/gorilla/websocket v1.5.1 // indirect + github.com/gorilla/websocket v1.5.3 // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect github.com/pierrec/xxHash v0.1.5 // indirect @@ -49,9 +49,9 @@ require ( github.com/stretchr/objx v0.5.2 // indirect github.com/vedhavyas/go-subkey/v2 v2.0.0 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/net v0.27.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.22.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 781a277..fbc0f4a 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ github.com/decred/base58 v1.0.4/go.mod h1:jJswKPEdvpFpvf7dsDvFZyLT22xZ9lWqEByX38 github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/ethereum/go-ethereum v1.10.20 h1:75IW830ClSS40yrQC1ZCMZCt5I+zU16oqId2SiQwdQ4= github.com/ethereum/go-ethereum v1.10.20/go.mod h1:LWUN82TCHGpxB3En5HVmLLzPD7YSrEUFmFfN1nKkVN0= @@ -52,10 +52,10 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -68,8 +68,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= +github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/reedsolomon v1.12.0 h1:I5FEp3xSwVCcEh3F5A7dofEfhXdF/bWhQWPH+XwBFno= github.com/klauspost/reedsolomon v1.12.0/go.mod h1:EPLZJeh4l27pUGC3aXOjheaoh1I9yut7xTURiW3LQ9Y= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -126,21 +126,21 @@ golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= -golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= +golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -148,8 +148,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/version.go b/version.go index bfaf4ee..0ec4fa4 100755 --- a/version.go +++ b/version.go @@ -8,4 +8,4 @@ package sdkgo // SDK Version -const Version = "0.6.1" +const Version = "0.6.2"