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

RPC methods to return error #542

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
70 changes: 35 additions & 35 deletions account/account.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func TestSignMOCK(t *testing.T) {
func TestAddInvoke(t *testing.T) {

type testSetType struct {
ExpectedError *rpc.RPCError
ExpectedError error
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpectedErr ?

CairoContractVersion int
SetKS bool
AccountAddress *felt.Felt
Expand Down Expand Up @@ -948,7 +948,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
Timeout time.Duration
ShouldCallTransactionReceipt bool
Hash *felt.Felt
ExpectedErr *rpc.RPCError
ExpectedErr error
ExpectedReceipt *rpc.TransactionReceiptWithBlockInfo
}
testSet := map[string][]testSetType{
Expand Down Expand Up @@ -1034,7 +1034,7 @@ func TestWaitForTransactionReceipt(t *testing.T) {
type testSetType struct {
Timeout int
Hash *felt.Felt
ExpectedErr *rpc.RPCError
ExpectedErr error
ExpectedReceipt rpc.TransactionReceipt
}
testSet := map[string][]testSetType{
Expand Down
6 changes: 3 additions & 3 deletions examples/deployAccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func main() {
}

// Send transaction to the network
resp, rpcErr := acnt.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})
if rpcErr != nil {
panic(fmt.Sprint("Error returned from AddDeployAccountTransaction: ", rpcErr))
resp, err := acnt.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})
if err != nil {
panic(fmt.Sprint("Error returned from AddDeployAccountTransaction: ", err))
kirugan marked this conversation as resolved.
Show resolved Hide resolved
}
fmt.Println("AddDeployAccountTransaction response:", resp)
}
12 changes: 6 additions & 6 deletions examples/deployAccountUDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func main() {
}

// Get the accounts nonce
nonce, rpcErr := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if rpcErr != nil {
panic(rpcErr)
nonce, err := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if err != nil {
panic(err)
}

// Build the InvokeTx struct
Expand Down Expand Up @@ -110,9 +110,9 @@ func main() {
}

// After the signing we finally call the AddInvokeTransaction in order to invoke the contract function
resp, rpcErr := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
if rpcErr != nil {
panic(rpcErr)
resp, err := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
if err != nil {
panic(err)
}
// This returns us with the transaction hash
fmt.Println("Transaction hash response : ", resp.TransactionHash)
Expand Down
12 changes: 6 additions & 6 deletions examples/estimateFee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func main() {
fmt.Println("Building transaction")

// Get the nonce from the account
nonce, rpcErr := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if rpcErr != nil {
panic(rpcErr)
nonce, err := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if err != nil {
panic(err)
}

// Build the InvokeTx struct
Expand Down Expand Up @@ -97,9 +97,9 @@ func main() {
}

fmt.Println("Calling EstimateFee")
resp, rpcErr := accnt.EstimateFee(context.Background(), []rpc.BroadcastTxn{InvokeTx}, []rpc.SimulationFlag{}, rpc.BlockID{Tag: "latest"})
if rpcErr != nil {
panic(fmt.Sprintf("Failed to estimate fee: %v", rpcErr))
resp, err := accnt.EstimateFee(context.Background(), []rpc.BroadcastTxn{InvokeTx}, []rpc.SimulationFlag{}, rpc.BlockID{Tag: "latest"})
if err != nil {
panic(fmt.Sprintf("Failed to estimate fee: %v", err))
}
fmt.Println("Fee estimated successfully")

Expand Down
6 changes: 3 additions & 3 deletions examples/simpleCall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func main() {
}

fmt.Println("Making Call() request")
callResp, rpcErr := clientv02.Call(context.Background(), tx, rpc.BlockID{Tag: "latest"})
if rpcErr != nil {
panic(rpcErr)
callResp, err := clientv02.Call(context.Background(), tx, rpc.BlockID{Tag: "latest"})
if err != nil {
panic(err)
}

fmt.Println(fmt.Sprintf("Response to %s():%s ", contractMethod, callResp[0]))
Expand Down
12 changes: 6 additions & 6 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func main() {
}

// Getting the nonce from the account
nonce, rpcErr := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if rpcErr != nil {
panic(rpcErr)
nonce, err := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if err != nil {
panic(err)
}

// Building the InvokeTx struct
Expand Down Expand Up @@ -104,9 +104,9 @@ func main() {
}

// After the signing we finally call the AddInvokeTransaction in order to invoke the contract function
resp, rpcErr := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
if rpcErr != nil {
panic(rpcErr)
resp, err := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
if err != nil {
panic(err)
}
// This returns us with the transaction hash
fmt.Println("Transaction hash response : ", resp.TransactionHash)
Expand Down
30 changes: 30 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,53 @@ require (
)

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/pebble v0.0.0-20230209222158-0568b5fd3d14 // indirect
github.com/cockroachdb/redact v1.1.3 // 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/getsentry/sentry-go v0.13.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spf13/pflag v1.0.5 // 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
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
google.golang.org/protobuf v1.28.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
Expand Down
Loading
Loading