Skip to content

Commit

Permalink
add pendingTransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoryguillou committed Aug 24, 2022
1 parent 5282067 commit 4c6296d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
var Curve StarkCurve

/*
Returned stark curve includes several values above and beyond
what the 'elliptic' interface calls for to facilitate common starkware functions
Returned stark curve includes several values above and beyond
what the 'elliptic' interface calls for to facilitate common starkware functions
*/
type StarkCurve struct {
*elliptic.CurveParams
Expand Down Expand Up @@ -280,7 +280,7 @@ func DivMod(n, m, p *big.Int) *big.Int {
q := new(big.Int)
gx := new(big.Int)
gy := new(big.Int)
q = q.GCD(gx, gy, m, p)
q.GCD(gx, gy, m, p)

r := new(big.Int).Mul(n, gx)
r = r.Mod(r, p)
Expand Down
14 changes: 7 additions & 7 deletions curve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

func BenchmarkPedersenHash(b *testing.B) {
suite := [][]*big.Int{
[]*big.Int{HexToBN("0x12773"), HexToBN("0x872362")},
[]*big.Int{HexToBN("0x1277312773"), HexToBN("0x872362872362")},
[]*big.Int{HexToBN("0x1277312773"), HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826")},
[]*big.Int{HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), HexToBN("0x872362872362")},
[]*big.Int{HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB")},
[]*big.Int{HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9")},
[]*big.Int{HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde")},
{HexToBN("0x12773"), HexToBN("0x872362")},
{HexToBN("0x1277312773"), HexToBN("0x872362872362")},
{HexToBN("0x1277312773"), HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826")},
{HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), HexToBN("0x872362872362")},
{HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB")},
{HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9")},
{HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde")},
}

for _, test := range suite {
Expand Down
22 changes: 17 additions & 5 deletions rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"strconv"
"strings"

Expand Down Expand Up @@ -35,13 +34,13 @@ func (sc *Client) Call(ctx context.Context, call types.FunctionCall, hash string
}

// BlockNumber gets the most recent accepted block number.
func (sc *Client) BlockNumber(ctx context.Context) (*big.Int, error) {
var blockNumber big.Int
func (sc *Client) BlockNumber(ctx context.Context) (uint64, error) {
var blockNumber uint64
if err := sc.c.CallContext(ctx, &blockNumber, "starknet_blockNumber"); err != nil {
return nil, err
return 0, err
}

return &blockNumber, nil
return blockNumber, nil
}

// BlockHashAndNumberOutput is a struct that is returned by BlockHashAndNumber.
Expand Down Expand Up @@ -150,6 +149,19 @@ type BlockWithTxHashes struct {
BlockBodyWithTxHashes
}

// PendingTransactions returns the list of pending transactions.
func (sc *Client) PendingTransactions(ctx context.Context) ([]Txn, error) {
var pendingTransactions []Txn
if err := sc.do(ctx, "starknet_pendingTransactions", &pendingTransactions); err != nil {
return nil, err
}
pendingTransactionWithTypes, err := guessTxsWithType(pendingTransactions)
if err != nil {
return nil, err
}
return pendingTransactionWithTypes, nil
}

// BlockWithTxHashes gets block information given the block id.
func (sc *Client) BlockWithTxHashes(ctx context.Context, blockIDOption BlockIDOption) (interface{}, error) {
opt := &blockID{}
Expand Down
2 changes: 1 addition & 1 deletion rpc/api_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestBlockNumber(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if blockNumber == nil || blockNumber.Int64() <= 0 {
if blockNumber == 0 {
t.Fatal("current block number should be higher or equal to 1")
}
}
Expand Down

0 comments on commit 4c6296d

Please sign in to comment.