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

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawliet-Chan committed Jan 20, 2024
1 parent e25ffaf commit c4ab7a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 7 additions & 1 deletion cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ func main() {
panic(err)
}

declareTx, class := cairoVM.NewDeclare("data/cool_sierra_contract_class.json")
declareTx, class, err := cairoVM.NewDeclare(
"data/cool_sierra_contract_class.json",
"data/cool_compiled_class.casm",
)
if err != nil {
panic(err)
}
// fmt.Println(declare_tx)

_, err = vm.HandleDeclareTx(declareTx, class)
Expand Down
15 changes: 7 additions & 8 deletions cairoVM/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,27 @@ func SetGenesis(state *core.State, dir string) error {
return state.Update(0, nil, classes)
}

func NewDeclare(sierraFileName string) (*core.DeclareTransaction, core.Class) {
func NewDeclare(sierraFileName, casmFileName string) (*core.DeclareTransaction, core.Class, error) {
// ref to https://github.com/NethermindEth/starknet.go/blob/915109ab5bc1c9c5bae7a71553a96e6665c0dcb2/account/account_test.go#L1116

content, err := os.ReadFile(sierraFileName)
if err != nil {
panic(err)
return nil, nil, err
}

var class rpc.ContractClass
err = json.Unmarshal(content, &class)
if err != nil {
panic(err)
return nil, nil, err
}
classHash, err := hash.ClassHash(class)

var casmClass contracts.CasmClass
err = json.Unmarshal(content, &casmClass)
casmClass, err := contracts.UnmarshalCasmClass(casmFileName)
if err != nil {
panic(err)
return nil, nil, err
}

compClassHash := hash.CompiledClassHash(casmClass)
compClassHash := hash.CompiledClassHash(*casmClass)

var nonce felt.Felt
nonce.SetUint64(0)
Expand All @@ -69,7 +68,7 @@ func NewDeclare(sierraFileName string) (*core.DeclareTransaction, core.Class) {

coreClass, err := adaptDeclaredClass(content)

return &tx, coreClass
return &tx, coreClass, err
}

func adaptClassAndHash(fileName string) (core.Class, *felt.Felt, error) {
Expand Down

0 comments on commit c4ab7a1

Please sign in to comment.