Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
add set cool value (#25)
Browse files Browse the repository at this point in the history
* add set cool value
---------

Signed-off-by: Qiang Zhou <[email protected]>
  • Loading branch information
zhouqiang-cl authored Feb 2, 2024
1 parent 9f89edb commit f1ac19a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 71 deletions.
6 changes: 3 additions & 3 deletions cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func main() {
}
spew.Dump(trace)

invokeTx, err = cairoVM.NewDeployInvokeTest()
invokeTx, err = cairoVM.SetCoolValue("0x7f2f788bcd85c25ece505a4fe359c577be77841c5afb971648af03391e5e834", 9099)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func main() {
}
spew.Dump(trace)

invokeTx, err = cairoVM.NewDeployInvokeTestCoolOld()
invokeTx, err = cairoVM.SetCoolValue("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9", 1111)
if err != nil {
panic(err)
}
Expand Down
64 changes: 0 additions & 64 deletions cairoVM/deploy.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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),
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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

}
10 changes: 6 additions & 4 deletions cairoVM/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,5 +40,4 @@ func NewInvoke() (*core.InvokeTransaction, error) {
}

return &tx, nil

}

0 comments on commit f1ac19a

Please sign in to comment.