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

Commit

Permalink
declare success
Browse files Browse the repository at this point in the history
Signed-off-by: Qiang Zhou <[email protected]>
  • Loading branch information
zhouqiang-cl committed Feb 1, 2024
1 parent 558dcdb commit 85c66f6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
27 changes: 25 additions & 2 deletions cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func main() {

// declare TX
declareTx, class, err := cairoVM.NewDeclare(
"data/erc20.sierra.json",
"data/erc20.casm.json",
"data/cool.sierra.json",
"data/cool.casm.json",
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -113,4 +113,27 @@ func main() {
}
spew.Dump(trace)

invokeTx, err = cairoVM.NewDeployInvokeTestCoolOld()
if err != nil {
panic(err)
}

trace, err = vm.HandleInvokeTx(invokeTx) // Assuming there is a HandleInvokeTx function
if err != nil {
panic(err)
}

new_address, _ = new(felt.Felt).SetString("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9")

resp, err = vm.HandleCall(&rpc.FunctionCall{
ContractAddress: *new_address,
EntryPointSelector: *utils.GetSelectorFromNameFelt("get_value"),
},
callClassHash,
)
if err != nil {
panic(err)
}
fmt.Println("call response", utils.FeltToBigInt(resp[0]))

}
41 changes: 39 additions & 2 deletions cairoVM/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) {
// using UniversalDeploy address
contractAddress := new(felt.Felt).SetUint64(1)

classHash, _ := new(felt.Felt).SetString("0x35eb1d3593b1fe9a8369a023ffa5d07d3b2050841cb75ad6ef00698d9307d10")
classHash, _ := new(felt.Felt).SetString("0x47f93257c3a6e42fc71162a646b3223dfad27c2d994f97f333492c66e31b8c8")

salt, _ := new(felt.Felt).SetString("0x53eb1d3593b1fe9a8369a023ffa5d07d3b2050841cb75ad6ef00698d9307d10")

Expand All @@ -128,7 +128,7 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) {

fmt.Println("invoke calldata = ", txCallData)

nonce := new(felt.Felt).SetUint64(2)
nonce := new(felt.Felt).SetUint64(4)
tx := core.InvokeTransaction{
Nonce: nonce,
MaxFee: &felt.Zero,
Expand All @@ -142,3 +142,40 @@ func NewDeployCoolOld() (*core.InvokeTransaction, error) {
return &tx, nil

}

func NewDeployInvokeTestCoolOld() (*core.InvokeTransaction, error) {
//InvokeTx := rpc.InvokeTxnV1{
// Version: rpc.TransactionV1,
// Type: rpc.TransactionType_Invoke,
//}

// Converting the contractAddress from hex to felt
// contractAddress := new(felt.Felt).SetUint64(2)
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)

nonce := new(felt.Felt).SetUint64(5)
tx := core.InvokeTransaction{
Nonce: nonce,
MaxFee: &felt.Zero,
Version: new(core.TransactionVersion).SetUint64(1),
ContractAddress: contractAddress,
EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod),
CallData: txCallData,
// CallData: []*felt.Felt{randata},
}

return &tx, nil

}

0 comments on commit 85c66f6

Please sign in to comment.