Skip to content

Commit

Permalink
Fix nknc genid not working
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang authored and gdmmx committed Sep 3, 2019
1 parent c4ac008 commit 684d747
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 4 additions & 4 deletions api/httpjson/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ func GetNonceByAddr(remote string, addr string) (uint64, uint32, error) {

var ret struct {
Result struct {
nonce uint64
nonceInTxPool uint64
currentHeight uint32
Nonce uint64
NonceInTxPool uint64
CurrentHeight uint32
} `json:"result"`
Err map[string]interface{} `json:"error"`
}
Expand All @@ -214,5 +214,5 @@ func GetNonceByAddr(remote string, addr string) (uint64, uint32, error) {
return 0, 0, fmt.Errorf("GetNonceByAddr(%s) resp error: %v", remote, string(resp))
}

return ret.Result.nonceInTxPool, ret.Result.currentHeight, nil
return ret.Result.NonceInTxPool, ret.Result.CurrentHeight, nil
}
22 changes: 20 additions & 2 deletions cli/id/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

. "github.com/nknorg/nkn/api/common"
"github.com/nknorg/nkn/api/httpjson/client"
"github.com/nknorg/nkn/chain"
. "github.com/nknorg/nkn/cli/common"
. "github.com/nknorg/nkn/common"
"github.com/nknorg/nkn/util/config"
Expand Down Expand Up @@ -52,7 +51,26 @@ func generateIDAction(c *cli.Context) error {
var resp []byte
switch {
case c.Bool("genid"):
txn, _ := MakeGenerateIDTransaction(context.Background(), myWallet, regFee, nonce, txnFee, config.MaxGenerateIDTxnHash.GetValueAtHeight(chain.DefaultLedger.Store.GetHeight()+1))
account, err := myWallet.GetDefaultAccount()
if err != nil {
return err
}

walletAddr, err := account.ProgramHash.ToAddress()
if err != nil {
return err
}

remoteNonce, height, err := client.GetNonceByAddr(Address(), walletAddr)
if err != nil {
return err
}

if nonce == 0 {
nonce = remoteNonce
}

txn, _ := MakeGenerateIDTransaction(context.Background(), myWallet, regFee, nonce, txnFee, config.MaxGenerateIDTxnHash.GetValueAtHeight(height+1))
buff, _ := txn.Marshal()
resp, err = client.Call(Address(), "sendrawtransaction", 0, map[string]interface{}{"tx": hex.EncodeToString(buff)})
default:
Expand Down

0 comments on commit 684d747

Please sign in to comment.