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

Commit

Permalink
call tx (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawliet-Chan authored Jan 31, 2024
1 parent 27d64f8 commit 4c26320
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions cairoVM/cairo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewCairoVM(cfg *Config) (*Cairo, error) {
}

func (c *Cairo) HandleCall(call *rpc.FunctionCall, classHash *felt.Felt) ([]*felt.Felt, error) {
fmt.Println("------------ Call ------------")
return c.vm.Call(&call.ContractAddress, classHash, &call.EntryPointSelector, call.Calldata, 0, uint64(time.Now().Unix()), c.state, c.cfg.Network)
}

Expand Down
19 changes: 19 additions & 0 deletions cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"fmt"
"github.com/NethermindEth/juno/rpc"
"github.com/NethermindEth/starknet.go/utils"
"github.com/davecgh/go-spew/spew"
"testbot/cairoVM"

Expand Down Expand Up @@ -45,6 +48,22 @@ func main() {
if err != nil {
panic(err)
}

callClassHash, err := new(felt.Felt).SetString("0x35eb1d3593b1fe9a8369a023ffa5d07d3b2050841cb75ad6ef00698d9307d10")
if err != nil {
panic(err)
}
spew.Dump(trace)

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

}
4 changes: 2 additions & 2 deletions cairoVM/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func NewDeclare(sierraFileName, casmFileName string) (*core.DeclareTransaction,
if err != nil {
return nil, nil, err
}
fmt.Println("ClassHash = ", classHash.String())
fmt.Println("Declare ClassHash = ", classHash.String())

casmClass, err := contracts.UnmarshalCasmClass(casmFileName)
if err != nil {
return nil, nil, err
}

compClassHash := hash.CompiledClassHash(*casmClass)
fmt.Println("CasmClass = ", compClassHash.String())
fmt.Println("Declare CasmClass = ", compClassHash.String())

var nonce felt.Felt
nonce.SetUint64(0)
Expand Down
3 changes: 2 additions & 1 deletion cairoVM/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func BuildGenesis(classesPaths []string) (*blockchain.PendingStateWriter, error)
return nil, fmt.Errorf("set compiled class hash: %v", err)
}
}

addrFelt := new(felt.Felt).SetUint64(addr)
fmt.Println("Genesis.SetClassHash = ", classHash.String())
err = genesisState.SetClassHash(addrFelt, &classHash)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cairoVM/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewInvoke() (*core.InvokeTransaction, error) {
// Converting the contractAddress from hex to felt
contractAddress := new(felt.Felt).SetUint64(2)

params := new(felt.Felt).SetUint64(111)
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
Expand Down

0 comments on commit 4c26320

Please sign in to comment.