Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#201: Call mempool.get_pending_nonce #202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/koinos/koinos-cli/cmd/cli/interactive"
"github.com/koinos/koinos-cli/internal/cli"
"github.com/koinos/koinos-cli/internal/cliutil"
util "github.com/koinos/koinos-util-golang"
util "github.com/koinos/koinos-util-golang/v2"
flag "github.com/spf13/pflag"
)

Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ require (
github.com/ethereum/go-ethereum v1.10.9 // indirect
github.com/joho/godotenv v1.3.0
github.com/koinos/go-prompt v0.0.0-20221201222302-dba4c3542a91
github.com/koinos/koinos-proto-golang v1.0.1-0.20221123003957-336b725f600d
github.com/koinos/koinos-util-golang v1.0.1-0.20221123171000-f256b12203af
github.com/koinos/koinos-proto-golang/v2 v2.3.0
github.com/koinos/koinos-util-golang/v2 v2.0.1
github.com/minio/sio v0.3.0
github.com/multiformats/go-multihash v0.1.0
github.com/shopspring/decimal v1.3.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.1
github.com/ybbus/jsonrpc/v3 v3.1.1
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.30.0
)

replace google.golang.org/protobuf => github.com/koinos/protobuf-go v1.27.2-0.20211026185306-2456c83214fe
1,162 changes: 1,146 additions & 16 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/cli/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/btcsuite/btcutil/base58"
"github.com/koinos/koinos-cli/internal/cliutil"
"github.com/koinos/koinos-proto-golang/koinos"
"github.com/koinos/koinos-proto-golang/koinos/chain"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
util "github.com/koinos/koinos-util-golang"
"github.com/koinos/koinos-proto-golang/v2/koinos"
"github.com/koinos/koinos-proto-golang/v2/koinos/chain"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
util "github.com/koinos/koinos-util-golang/v2"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/koinos/koinos-cli/internal/cliutil"
util "github.com/koinos/koinos-util-golang"
util "github.com/koinos/koinos-util-golang/v2"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

"github.com/btcsuite/btcutil/base58"
"github.com/koinos/koinos-cli/internal/cliutil"
kjson "github.com/koinos/koinos-proto-golang/encoding/json"
"github.com/koinos/koinos-proto-golang/koinos/chain"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
kjson "github.com/koinos/koinos-proto-golang/v2/encoding/json"
"github.com/koinos/koinos-proto-golang/v2/koinos/chain"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
"github.com/shopspring/decimal"
"google.golang.org/protobuf/proto"

util "github.com/koinos/koinos-util-golang"
util "github.com/koinos/koinos-util-golang/v2"
)

// CommandSet represents a set of commands for the parser
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/contract_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

"github.com/btcsuite/btcutil/base58"
"github.com/koinos/koinos-cli/internal/cliutil"
"github.com/koinos/koinos-proto-golang/encoding/text"
"github.com/koinos/koinos-proto-golang/koinos"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
"github.com/koinos/koinos-proto-golang/v2/encoding/text"
"github.com/koinos/koinos-proto-golang/v2/koinos"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/descriptorpb"
Expand Down
13 changes: 10 additions & 3 deletions internal/cli/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/btcsuite/btcutil/base58"
"github.com/koinos/koinos-cli/internal/cliutil"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
util "github.com/koinos/koinos-util-golang"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
util "github.com/koinos/koinos-util-golang/v2"
"github.com/shopspring/decimal"
)

Expand Down Expand Up @@ -161,11 +161,18 @@ func (ee *ExecutionEnvironment) GetNextNonce(ctx context.Context, update bool) (
}

if nInfo.nonceTime.IsZero() || time.Since(nInfo.nonceTime) > NonceCheckTime {
nonce, err := ee.RPCClient.GetAccountNonce(ctx, ee.Key.AddressBytes())
nonce, err := ee.RPCClient.GetPendingNonce(ctx, ee.Key.AddressBytes())
if err != nil {
return 0, err
}

if nonce == 0 {
nonce, err = ee.RPCClient.GetAccountNonce(ctx, ee.Key.AddressBytes())
if err != nil {
return 0, err
}
}

nInfo.nonceTime = time.Now()
atomic.StoreUint64(&nInfo.currentNonce, nonce)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"errors"

"github.com/koinos/koinos-proto-golang/koinos/protocol"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/token_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"github.com/btcsuite/btcutil/base58"
"github.com/koinos/koinos-cli/internal/cliutil"
"github.com/koinos/koinos-proto-golang/koinos/contracts/token"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
util "github.com/koinos/koinos-util-golang"
"github.com/koinos/koinos-proto-golang/v2/koinos/contracts/token"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
util "github.com/koinos/koinos-util-golang/v2"
"github.com/shopspring/decimal"
"google.golang.org/protobuf/proto"
)
Expand Down
42 changes: 35 additions & 7 deletions internal/cliutil/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"

kjson "github.com/koinos/koinos-proto-golang/encoding/json"
"github.com/koinos/koinos-proto-golang/koinos/contract_meta_store"
"github.com/koinos/koinos-proto-golang/koinos/contracts/token"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
"github.com/koinos/koinos-proto-golang/koinos/rpc/chain"
contract_meta_store_rpc "github.com/koinos/koinos-proto-golang/koinos/rpc/contract_meta_store"
util "github.com/koinos/koinos-util-golang"
kjson "github.com/koinos/koinos-proto-golang/v2/encoding/json"
"github.com/koinos/koinos-proto-golang/v2/koinos/contract_meta_store"
"github.com/koinos/koinos-proto-golang/v2/koinos/contracts/token"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
"github.com/koinos/koinos-proto-golang/v2/koinos/rpc/chain"
contract_meta_store_rpc "github.com/koinos/koinos-proto-golang/v2/koinos/rpc/contract_meta_store"
"github.com/koinos/koinos-proto-golang/v2/koinos/rpc/mempool"
util "github.com/koinos/koinos-util-golang/v2"
jsonrpc "github.com/ybbus/jsonrpc/v3"
"google.golang.org/protobuf/proto"
)
Expand All @@ -23,6 +24,7 @@ const (
SubmitTransactionCall = "chain.submit_transaction"
GetChainIDCall = "chain.get_chain_id"
GetContractMetaCall = "contract_meta_store.get_contract_meta"
GetPendingNonceCall = "mempool.get_pending_nonce"
)

// SubmissionParams is the parameters for a transaction submission
Expand Down Expand Up @@ -279,3 +281,29 @@ func (c *KoinosRPCClient) GetChainID(ctx context.Context) ([]byte, error) {

return cResp.ChainId, nil
}

// GetPendingNonce gets the pending nonce from the mempool
func (c *KoinosRPCClient) GetPendingNonce(ctx context.Context, address []byte) (uint64, error) {
// Build the request
params := mempool.GetPendingNonceRequest{
Payee: address,
}

// Make the rpc call
var mResp mempool.GetPendingNonceResponse
err := c.Call(ctx, GetPendingNonceCall, &params, &mResp)
if err != nil {
return 0, err
}

if mResp.Nonce == nil {
return 0, nil
}

nonce, err := util.NonceBytesToUInt64(mResp.Nonce)
if err != nil {
return 0, err
}

return nonce, nil
}
6 changes: 3 additions & 3 deletions internal/cliutil/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"crypto/sha256"

"github.com/btcsuite/btcd/btcec"
"github.com/koinos/koinos-proto-golang/koinos/canonical"
"github.com/koinos/koinos-proto-golang/koinos/protocol"
util "github.com/koinos/koinos-util-golang"
"github.com/koinos/koinos-proto-golang/v2/koinos/canonical"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
util "github.com/koinos/koinos-util-golang/v2"
"github.com/multiformats/go-multihash"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/cliutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"os"

"github.com/koinos/koinos-proto-golang/koinos/protocol"
util "github.com/koinos/koinos-util-golang"
"github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
util "github.com/koinos/koinos-util-golang/v2"
"github.com/minio/sio"
)

Expand Down