Skip to content

Commit

Permalink
Merge branch 'main' into rpcv05-block-header-update
Browse files Browse the repository at this point in the history
  • Loading branch information
cicr99 committed Oct 25, 2023
2 parents 23a8933 + 04f9adc commit be99e2d
Show file tree
Hide file tree
Showing 35 changed files with 579 additions and 260 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main_ci_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ jobs:
- 5050:5050

steps:
- uses: actions/checkout@v3
- name: Checkout branch
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version-file: go.mod

- name: wait for devnet to be up...
run: ./.bin/devnet.sh
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ jobs:
- 5050:5050

steps:
- uses: actions/checkout@v3
- name: Checkout branch
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version-file: go.mod

- name: wait for devnet to be up...
run: ./.bin/devnet.sh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4.1.0
uses: actions/setup-go@v4
with:
go-version-file: go.mod

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test_rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ jobs:
- 5050:5050

steps:
- uses: actions/checkout@v3
- name: Checkout branch
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version-file: go.mod

- name: wait for devnet to be up...
run: ./.bin/devnet.sh
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ go run main.go
| `starknet_getTransactionByHash` | :heavy_check_mark: |
| `starknet_getTransactionByBlockIdAndIndex` | :heavy_check_mark: |
| `starknet_getTransactionReceipt` | :heavy_check_mark: |
| `starknet_getTransactionStatus` | :heavy_check_mark: |
| `starknet_getClass` | :heavy_check_mark: |
| `starknet_getClassHashAt` | :heavy_check_mark: |
| `starknet_getClassAt` | :heavy_check_mark: |
Expand Down
12 changes: 8 additions & 4 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,16 @@ func (account *Account) Syncing(ctx context.Context) (*rpc.SyncStatus, error) {
return account.provider.Syncing(ctx)
}

func (account *Account) TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]rpc.Trace, error) {
return account.provider.TraceBlockTransactions(ctx, blockHash)
func (account *Account) TraceBlockTransactions(ctx context.Context, blockID rpc.BlockID) ([]rpc.Trace, error) {
return account.provider.TraceBlockTransactions(ctx, blockID)
}

func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (rpc.TransactionReceipt, error) {
return account.provider.TransactionReceipt(ctx, transactionHash)
}

func (account *Account) TransactionTrace(ctx context.Context, transactionHash *felt.Felt) (rpc.TxnTrace, error) {
return account.provider.TransactionTrace(ctx, transactionHash)
func (account *Account) TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (rpc.TxnTrace, error) {
return account.provider.TraceTransaction(ctx, transactionHash)
}

func (account *Account) TransactionByBlockIdAndIndex(ctx context.Context, blockID rpc.BlockID, index uint64) (rpc.Transaction, error) {
Expand All @@ -416,6 +416,10 @@ func (account *Account) TransactionByHash(ctx context.Context, hash *felt.Felt)
return account.provider.TransactionByHash(ctx, hash)
}

func (account *Account) GetTransactionStatus(ctx context.Context, Txnhash *felt.Felt) (*rpc.TxnStatusResp, error) {
return account.provider.GetTransactionStatus(ctx, Txnhash)
}

func (account *Account) FmtCalldata(fnCalls []rpc.FunctionCall, cairoVersion int) ([]*felt.Felt, error) {
switch cairoVersion {
case 0:
Expand Down
1 change: 0 additions & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ func TestAddDeclareTxn(t *testing.T) {
SenderAddress: AccountAddress,
CompiledClassHash: compClassHash,
ClassHash: classHash,
ContractClass: class,
}

err = acnt.SignDeclareTransaction(context.Background(), &tx)
Expand Down
6 changes: 4 additions & 2 deletions examples/deployAccount/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module account

go 1.18
go 1.21

require (
github.com/NethermindEth/juno v0.3.1
Expand All @@ -14,14 +14,15 @@ replace github.com/NethermindEth/starknet.go => ../../
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.11.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/stretchr/testify v1.8.1 // indirect
Expand All @@ -33,4 +34,5 @@ require (
golang.org/x/sys v0.3.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
2 changes: 1 addition & 1 deletion examples/deployAccount/go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.18
go 1.21

use (
.
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleCall/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module account

go 1.18
go 1.21

require (
github.com/NethermindEth/starknet.go v0.2.1-0.20220620163912-1db2ca279608
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleCall/go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.18
go 1.21

use (
.
Expand Down
9 changes: 9 additions & 0 deletions examples/simpleInvoke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Note: To run this example, you need a testnet endpoint.

Steps to run this example on mainnet:

1. rename ".env.template" to ".env.testnet"
2. uncomment, and set INTEGRATION_BASE to the testnet url //You can get it from here www.alchemy.com/starknet
3. make sure you are in the "simpleInvoke" directory
4. execute `go mod tidy`
5. execute `go run main.go`
33 changes: 33 additions & 0 deletions examples/simpleInvoke/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module account

go 1.20

require (
github.com/NethermindEth/juno v0.3.1
github.com/NethermindEth/starknet.go v0.4.6-0.20231005024141-742a82479868
github.com/ethereum/go-ethereum v1.10.26
github.com/joho/godotenv v1.4.0
)

require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/consensys/gnark-crypto v0.11.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/test-go/testify v1.1.4 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.2.0 // indirect
golang.org/x/sys v0.3.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions examples/simpleInvoke/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
../..
)
120 changes: 120 additions & 0 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package main

import (
"context"
"fmt"
"math/big"
"os"

"github.com/NethermindEth/starknet.go/account"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/joho/godotenv"
)

// NOTE : Please add in your keys only for testing purposes, incase of a leak you would potentially lose your funds.
var (
name string = "testnet" //env."name"
account_addr string = "0x06f36e8a0fc06518125bbb1c63553e8a7d8597d437f9d56d891b8c7d3c977716" //Replace it with your account address
privateKey string = "0x0687bf84896ee63f52d69e6de1b41492abeadc0dc3cb7bd351d0a52116915937" //Replace it with your account private key
public_key string = "0x58b0824ee8480133cad03533c8930eda6888b3c5170db2f6e4f51b519141963" //Replace it with your account public key
someContract string = "0x4c1337d55351eac9a0b74f3b8f0d3928e2bb781e5084686a892e66d49d510d" //Replace it with the contract that you want to invoke
contractMethod string = "increase_value" //Replace it with the function name that you want to invoke
)

func main() {
//Loading the env
godotenv.Load(fmt.Sprintf(".env.%s", name))
base := os.Getenv("INTEGRATION_BASE") //please modify the .env.testnet and replace the INTEGRATION_BASE with an starknet goerli RPC.
fmt.Println("Starting simpleInvoke example")

//Initialising the connection
c, err := ethrpc.DialContext(context.Background(), base)
if err != nil {
fmt.Println("Failed to connect to the client, did you specify the url in the .env.testnet?")
panic(err)
}

//Initialising the provider
clientv02 := rpc.NewProvider(c)

//Here we are converting the account address to felt
account_address, err := utils.HexToFelt(account_addr)
if err != nil {
panic(err.Error())
}
//Initializing the account memkeyStore
ks := account.NewMemKeystore()
fakePrivKeyBI, ok := new(big.Int).SetString(privateKey, 0)
if !ok {
panic(err.Error())
}
ks.Put(public_key, fakePrivKeyBI)

fmt.Println("Established connection with the client")

//Here we are setting the maxFee
maxfee, err := utils.HexToFelt("0x9184e72a000")
if err != nil {
panic(err.Error())
}

//Initializing the account
accnt, err := account.NewAccount(clientv02, account_address, public_key, ks)
if err != nil {
panic(err.Error())
}

//Getting the nonce from the account, and then converting it into felt
nonce_string, _ := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
nonce, err := utils.HexToFelt(*nonce_string)
if err != nil {
panic(err.Error())
}

//Building the InvokeTx struct
InvokeTx := rpc.InvokeTxnV1{
MaxFee: maxfee,
Version: rpc.TransactionV1,
Nonce: nonce,
Type: rpc.TransactionType_Invoke,
SenderAddress: accnt.AccountAddress,
}

//Converting the contractaddress from hex to felt
contractAddress, err := utils.HexToFelt(someContract)
if err != nil {
panic(err.Error())
}

//Building the functioncall struct, where :
FnCall := rpc.FunctionCall{
ContractAddress: contractAddress, //contractAddress is the contract that we wanna call
EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), //this is the function that we wanna call
}

//Mentioning the contract version
CairoContractVersion := 2

//Building the Calldata with the help of FmtCalldata where we pass in the FnCall struct along with the Cairo version
InvokeTx.Calldata, err = accnt.FmtCalldata([]rpc.FunctionCall{FnCall}, CairoContractVersion)
if err != nil {
panic(err.Error())
}

//Signing of the the transaction that is done by the account
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx)
if err != nil {
panic(err.Error())
}

//After the signing we finally call the AddInvokeTransaction in order to invoke the contract function
resp, err := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
if err != nil {
panic(err.Error())
}
//This returns us with the transaction hash
fmt.Println("Response : ", resp.TransactionHash)

}
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/NethermindEth/starknet.go

go 1.18
go 1.21

require (
github.com/NethermindEth/juno v0.3.1
Expand All @@ -10,7 +10,6 @@ require (
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/pkg/errors v0.9.1
github.com/test-go/testify v1.1.4
github.com/urfave/cli/v2 v2.10.2
golang.org/x/crypto v0.2.0
)

Expand All @@ -19,7 +18,6 @@ require (
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.11.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
Expand All @@ -28,20 +26,17 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require (
github.com/google/go-cmp v0.5.7
github.com/google/go-querystring v1.1.0
golang.org/x/sys v0.3.0 // indirect
)
Loading

0 comments on commit be99e2d

Please sign in to comment.