From f1ac19ab4fe87ee596eeac3b589f5f3ced7f39c2 Mon Sep 17 00:00:00 2001 From: zhouqiang Date: Fri, 2 Feb 2024 12:40:25 +0800 Subject: [PATCH] add set cool value (#25) * add set cool value --------- Signed-off-by: Qiang Zhou --- cairoVM/cmd/main.go | 6 ++--- cairoVM/deploy.go | 64 --------------------------------------------- cairoVM/invoke.go | 10 ++++--- 3 files changed, 9 insertions(+), 71 deletions(-) diff --git a/cairoVM/cmd/main.go b/cairoVM/cmd/main.go index ba76553..ab85a76 100644 --- a/cairoVM/cmd/main.go +++ b/cairoVM/cmd/main.go @@ -39,7 +39,7 @@ func main() { } spew.Dump(trace) - invokeTx, err := cairoVM.NewInvoke() + invokeTx, err := cairoVM.SetCoolValue(cairoVM.CoolContractAddress, 8088) if err != nil { panic(err) } @@ -78,7 +78,7 @@ func main() { } spew.Dump(trace) - invokeTx, err = cairoVM.NewDeployInvokeTest() + invokeTx, err = cairoVM.SetCoolValue("0x7f2f788bcd85c25ece505a4fe359c577be77841c5afb971648af03391e5e834", 9099) if err != nil { panic(err) } @@ -112,7 +112,7 @@ func main() { } spew.Dump(trace) - invokeTx, err = cairoVM.NewDeployInvokeTestCoolOld() + invokeTx, err = cairoVM.SetCoolValue("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9", 1111) if err != nil { panic(err) } diff --git a/cairoVM/deploy.go b/cairoVM/deploy.go index bdfe5ff..9683887 100644 --- a/cairoVM/deploy.go +++ b/cairoVM/deploy.go @@ -1,8 +1,6 @@ package cairoVM import ( - "fmt" - "github.com/NethermindEth/juno/core" "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/account" @@ -44,10 +42,7 @@ func NewDeployCool() (*core.InvokeTransaction, error) { txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall}) - nonce := new(felt.Felt).SetUint64(2) tx := core.InvokeTransaction{ - Nonce: nonce, - MaxFee: &felt.Zero, Version: new(core.TransactionVersion).SetUint64(1), ContractAddress: contractAddress, EntryPointSelector: utils.GetSelectorFromNameFelt(deployContractMethod), @@ -57,33 +52,6 @@ func NewDeployCool() (*core.InvokeTransaction, error) { } -func NewDeployInvokeTest() (*core.InvokeTransaction, error) { - contractAddress, _ := new(felt.Felt).SetString("0x7f2f788bcd85c25ece505a4fe359c577be77841c5afb971648af03391e5e834") - - params := new(felt.Felt).SetUint64(9099) - // Building the functionCall struct, where : - FnCall := rpc.FunctionCall{ - ContractAddress: contractAddress, //contractAddress is the contract that we want to call - EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), //this is the function that we want to call - Calldata: []*felt.Felt{params}, //this is the data that we want to pass to the function - } - - txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall}) - - fmt.Println("invoke calldata = ", txCallData) - - tx := core.InvokeTransaction{ - Version: new(core.TransactionVersion).SetUint64(1), - ContractAddress: contractAddress, - EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), - CallData: txCallData, - // CallData: []*felt.Felt{randata}, - } - - return &tx, nil - -} - func NewDeployCoolOld() (*core.InvokeTransaction, error) { contractAddress := new(felt.Felt).SetUint64(1) @@ -95,10 +63,6 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) { calldataLength := new(felt.Felt).SetUint64(0) - // calldata := felt.Felt{} - - // params := new(felt.Felt).SetUint64(8088) - // Building the functionCall struct, where : FnCall := rpc.FunctionCall{ ContractAddress: contractAddress, //contractAddress is the contract that we want to call EntryPointSelector: utils.GetSelectorFromNameFelt(deployContractMethod), //this is the function that we want to call @@ -107,8 +71,6 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) { txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall}) - fmt.Println("invoke calldata = ", txCallData) - tx := core.InvokeTransaction{ Version: new(core.TransactionVersion).SetUint64(1), ContractAddress: contractAddress, @@ -119,29 +81,3 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) { return &tx, nil } - -func NewDeployInvokeTestCoolOld() (*core.InvokeTransaction, error) { - contractAddress, _ := new(felt.Felt).SetString("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9") - - params := new(felt.Felt).SetUint64(1111) - // Building the functionCall struct, where : - FnCall := rpc.FunctionCall{ - ContractAddress: contractAddress, //contractAddress is the contract that we want to call - EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), //this is the function that we want to call - Calldata: []*felt.Felt{params}, //this is the data that we want to pass to the function - } - - txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall}) - - fmt.Println("invoke calldata = ", txCallData) - - tx := core.InvokeTransaction{ - Version: new(core.TransactionVersion).SetUint64(1), - ContractAddress: contractAddress, - EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), - CallData: txCallData, - } - - return &tx, nil - -} diff --git a/cairoVM/invoke.go b/cairoVM/invoke.go index ff862fb..3709ae7 100644 --- a/cairoVM/invoke.go +++ b/cairoVM/invoke.go @@ -14,10 +14,13 @@ var ( contractMethod string = "set_value" ) -func NewInvoke() (*core.InvokeTransaction, error) { - contractAddress := new(felt.Felt).SetUint64(2) +func SetCoolValue(address string, value uint64) (*core.InvokeTransaction, error) { + contractAddress, err := new(felt.Felt).SetString(address) + if err != nil { + return nil, err + } - params := new(felt.Felt).SetUint64(8088) + params := new(felt.Felt).SetUint64(value) FnCall := rpc.FunctionCall{ ContractAddress: contractAddress, //contractAddress is the contract that we want to call @@ -37,5 +40,4 @@ func NewInvoke() (*core.InvokeTransaction, error) { } return &tx, nil - }