diff --git a/account/account_test.go b/account/account_test.go index cb2e68fd..250b1b5c 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -16,7 +16,6 @@ import ( "github.com/NethermindEth/starknet.go/mocks" "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/test" - "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" "github.com/golang/mock/gomock" "github.com/test-go/testify/require" @@ -166,7 +165,7 @@ func TestFmtCallData(t *testing.T) { { FnCall: rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), - EntryPointSelector: types.GetSelectorFromNameFelt("transfer"), + EntryPointSelector: utils.GetSelectorFromNameFelt("transfer"), Calldata: utils.TestHexArrToFelt(t, []string{ "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", "0x1"}), @@ -343,7 +342,7 @@ func TestAddInvoke(t *testing.T) { }, FnCall: rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), - EntryPointSelector: types.GetSelectorFromNameFelt("transfer"), + EntryPointSelector: utils.GetSelectorFromNameFelt("transfer"), Calldata: []*felt.Felt{ utils.TestHexToFelt(t, "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), utils.TestHexToFelt(t, "0x1"), @@ -367,7 +366,7 @@ func TestAddInvoke(t *testing.T) { }, FnCall: rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x03E85bFbb8E2A42B7BeaD9E88e9A1B19dbCcf661471061807292120462396ec9"), - EntryPointSelector: types.GetSelectorFromNameFelt("burn"), + EntryPointSelector: utils.GetSelectorFromNameFelt("burn"), Calldata: []*felt.Felt{ utils.TestHexToFelt(t, "0x043784df59268c02b716e20bf77797bd96c68c2f100b2a634e448c35e3ad363e"), utils.TestHexToFelt(t, "0x1"), diff --git a/artifacts/artifacts.go b/artifacts/artifacts.go index d58a81b0..f670c4e3 100644 --- a/artifacts/artifacts.go +++ b/artifacts/artifacts.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) //go:embed account.json @@ -41,7 +41,7 @@ func AccountV0Formater(accountHash, pluginHash, publicKey string) ([]string, err return calldata, nil } calldata = append(calldata, accountHash) - initialize := fmt.Sprintf("0x%x", types.GetSelectorFromName("initialize")) + initialize := fmt.Sprintf("0x%x", utils.GetSelectorFromName("initialize")) calldata = append(calldata, initialize) paramLen := "0x1" if pluginHash != "" { @@ -68,7 +68,7 @@ func AccountFormater(accountHash, pluginHash, publicKey string) ([]string, error return calldata, nil } calldata = append(calldata, accountHash) - initialize := fmt.Sprintf("0x%x", types.GetSelectorFromName("initialize")) + initialize := fmt.Sprintf("0x%x", utils.GetSelectorFromName("initialize")) calldata = append(calldata, initialize) calldata = append(calldata, "0x1") @@ -83,7 +83,7 @@ func AccountPluginFormater(accountHash, pluginHash, publicKey string) ([]string, calldata := []string{} if accountHash != "" { calldata = append(calldata, accountHash) - initialize := fmt.Sprintf("0x%x", types.GetSelectorFromName("initialize")) + initialize := fmt.Sprintf("0x%x", utils.GetSelectorFromName("initialize")) calldata = append(calldata, initialize) calldata = append(calldata, "0x4") } diff --git a/contracts/contracts.go b/contracts/contracts.go index cf49614a..2e5dbb27 100644 --- a/contracts/contracts.go +++ b/contracts/contracts.go @@ -24,7 +24,7 @@ type DeployOutput struct { type ProviderType string const ( - ProviderRPC ProviderType = "rpc" + ProviderRPC ProviderType = "rpc" ) func (p *RPCProvider) declareAndWaitWithWallet(ctx context.Context, compiledClass []byte) (*DeclareOutput, error) { @@ -57,7 +57,7 @@ func (p *RPCProvider) declareAndWaitWithWallet(ctx context.Context, compiledClas // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, err // } - // if types.TransactionState(status.String()) == types.TransactionRejected { + // if utils.TransactionState(status.String()) == utils.TransactionRejected { // log.Printf("class Hash: %s\n", tx.ClassHash) // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, errors.New("declare rejected") @@ -108,7 +108,7 @@ func (p *RPCProvider) deployAccountAndWaitNoWallet(ctx context.Context, classHas // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, err // } - // if types.TransactionState(status.String()) == types.TransactionRejected { + // if utils.TransactionState(status.String()) == utils.TransactionRejected { // log.Printf("contract Address: %s\n", tx.ContractAddress) // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, errors.New("deploy rejected") @@ -160,7 +160,7 @@ func (p *RPCProvider) deployAndWaitWithWallet(ctx context.Context, compiledClass // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, err // } - // if types.TransactionState(status.String()) == types.TransactionRejected { + // if utils.TransactionState(status.String()) == utils.TransactionRejected { // log.Printf("contract Address: %s\n", tx.ContractAddress) // log.Printf("transaction Hash: %s\n", tx.TransactionHash) // return nil, errors.New("deploy rejected") diff --git a/contracts/contracts_test.go b/contracts/contracts_test.go index 91ee9ae6..0bd66f11 100644 --- a/contracts/contracts_test.go +++ b/contracts/contracts_test.go @@ -3,6 +3,7 @@ package contracts import ( "context" "fmt" + // "math/big" "testing" "time" @@ -13,7 +14,6 @@ import ( // "github.com/NethermindEth/starknet.go/account" "github.com/NethermindEth/starknet.go/artifacts" // devtest "github.com/NethermindEth/starknet.go/test" - // "github.com/NethermindEth/starknet.go/types" // "github.com/NethermindEth/starknet.go/utils" ) @@ -88,7 +88,7 @@ func TestRPC_InstallCounter(t *testing.T) { // ks := starknetgo.NewMemKeystore() // fakeSenderAddress := test.privateKey -// k := types.SNValToBN(test.privateKey) +// k := utils.SNValToBN(test.privateKey) // ks.Put(fakeSenderAddress, k) // switch test.providerType { // case ProviderRPC: @@ -121,7 +121,7 @@ func TestRPC_InstallCounter(t *testing.T) { // default: // t.Fatal("unsupported client type", test.providerType) // } -// tx, err := acc.Execute(ctx, []types.FunctionCall{{ContractAddress: utils.TestHexToFelt(t, counterTransaction.ContractAddress), EntryPointSelector: types.GetSelectorFromNameFelt("increment"), Calldata: []*felt.Felt{}}}, types.ExecuteDetails{}) +// tx, err := acc.Execute(ctx, []utils.FunctionCall{{ContractAddress: utils.TestHexToFelt(t, counterTransaction.ContractAddress), EntryPointSelector: utils.GetSelectorFromNameFelt("increment"), Calldata: []*felt.Felt{}}}, utils.ExecuteDetails{}) // if err != nil { // t.Fatal("should succeed, instead", err) // } diff --git a/curve_test.go b/curve_test.go index 31911379..a18129cd 100644 --- a/curve_test.go +++ b/curve_test.go @@ -5,18 +5,18 @@ import ( "math/big" "testing" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) func BenchmarkPedersenHash(b *testing.B) { suite := [][]*big.Int{ - {types.HexToBN("0x12773"), types.HexToBN("0x872362")}, - {types.HexToBN("0x1277312773"), types.HexToBN("0x872362872362")}, - {types.HexToBN("0x1277312773"), types.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826")}, - {types.HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), types.HexToBN("0x872362872362")}, - {types.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), types.HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB")}, - {types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), types.HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9")}, - {types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde")}, + {utils.HexToBN("0x12773"), utils.HexToBN("0x872362")}, + {utils.HexToBN("0x1277312773"), utils.HexToBN("0x872362872362")}, + {utils.HexToBN("0x1277312773"), utils.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826")}, + {utils.HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), utils.HexToBN("0x872362872362")}, + {utils.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), utils.HexToBN("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB")}, + {utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), utils.HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9")}, + {utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde")}, } for _, test := range suite { @@ -67,16 +67,16 @@ func TestGeneral_PedersenHash(t *testing.T) { expected *big.Int }{ { - elements: []*big.Int{types.HexToBN("0x12773"), types.HexToBN("0x872362")}, - expected: types.HexToBN("0x5ed2703dfdb505c587700ce2ebfcab5b3515cd7e6114817e6026ec9d4b364ca"), + elements: []*big.Int{utils.HexToBN("0x12773"), utils.HexToBN("0x872362")}, + expected: utils.HexToBN("0x5ed2703dfdb505c587700ce2ebfcab5b3515cd7e6114817e6026ec9d4b364ca"), }, { - elements: []*big.Int{types.HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9"), types.HexToBN("0x537461726b4e6574204d61696c")}, - expected: types.HexToBN("0x180c0a3d13c1adfaa5cbc251f4fc93cc0e26cec30ca4c247305a7ce50ac807c"), + elements: []*big.Int{utils.HexToBN("0x13d41f388b8ea4db56c5aa6562f13359fab192b3db57651af916790f9debee9"), utils.HexToBN("0x537461726b4e6574204d61696c")}, + expected: utils.HexToBN("0x180c0a3d13c1adfaa5cbc251f4fc93cc0e26cec30ca4c247305a7ce50ac807c"), }, { elements: []*big.Int{big.NewInt(100), big.NewInt(1000)}, - expected: types.HexToBN("0x45a62091df6da02dce4250cb67597444d1f465319908486b836f48d0f8bf6e7"), + expected: utils.HexToBN("0x45a62091df6da02dce4250cb67597444d1f465319908486b836f48d0f8bf6e7"), }, } @@ -98,14 +98,14 @@ func TestGeneral_DivMod(t *testing.T) { expected *big.Int }{ { - x: types.StrToBig("311379432064974854430469844112069886938521247361583891764940938105250923060"), - y: types.StrToBig("621253665351494585790174448601059271924288186997865022894315848222045687999"), - expected: types.StrToBig("2577265149861519081806762825827825639379641276854712526969977081060187505740"), + x: utils.StrToBig("311379432064974854430469844112069886938521247361583891764940938105250923060"), + y: utils.StrToBig("621253665351494585790174448601059271924288186997865022894315848222045687999"), + expected: utils.StrToBig("2577265149861519081806762825827825639379641276854712526969977081060187505740"), }, { x: big.NewInt(1), y: big.NewInt(2), - expected: types.HexToBN("0x0400000000000008800000000000000000000000000000000000000000000001"), + expected: utils.HexToBN("0x0400000000000008800000000000000000000000000000000000000000000001"), }, } @@ -126,16 +126,16 @@ func TestGeneral_Add(t *testing.T) { expectedY *big.Int }{ { - x: types.StrToBig("1468732614996758835380505372879805860898778283940581072611506469031548393285"), - y: types.StrToBig("1402551897475685522592936265087340527872184619899218186422141407423956771926"), - expectedX: types.StrToBig("2573054162739002771275146649287762003525422629677678278801887452213127777391"), - expectedY: types.StrToBig("3086444303034188041185211625370405120551769541291810669307042006593736192813"), + x: utils.StrToBig("1468732614996758835380505372879805860898778283940581072611506469031548393285"), + y: utils.StrToBig("1402551897475685522592936265087340527872184619899218186422141407423956771926"), + expectedX: utils.StrToBig("2573054162739002771275146649287762003525422629677678278801887452213127777391"), + expectedY: utils.StrToBig("3086444303034188041185211625370405120551769541291810669307042006593736192813"), }, { x: big.NewInt(1), y: big.NewInt(2), - expectedX: types.StrToBig("225199957243206662471193729647752088571005624230831233470296838210993906468"), - expectedY: types.StrToBig("190092378222341939862849656213289777723812734888226565973306202593691957981"), + expectedX: utils.StrToBig("225199957243206662471193729647752088571005624230831233470296838210993906468"), + expectedY: utils.StrToBig("190092378222341939862849656213289777723812734888226565973306202593691957981"), }, } @@ -160,11 +160,11 @@ func TestGeneral_MultAir(t *testing.T) { expectedY *big.Int }{ { - r: types.StrToBig("2458502865976494910213617956670505342647705497324144349552978333078363662855"), - x: types.StrToBig("1468732614996758835380505372879805860898778283940581072611506469031548393285"), - y: types.StrToBig("1402551897475685522592936265087340527872184619899218186422141407423956771926"), - expectedX: types.StrToBig("182543067952221301675635959482860590467161609552169396182763685292434699999"), - expectedY: types.StrToBig("3154881600662997558972388646773898448430820936643060392452233533274798056266"), + r: utils.StrToBig("2458502865976494910213617956670505342647705497324144349552978333078363662855"), + x: utils.StrToBig("1468732614996758835380505372879805860898778283940581072611506469031548393285"), + y: utils.StrToBig("1402551897475685522592936265087340527872184619899218186422141407423956771926"), + expectedX: utils.StrToBig("182543067952221301675635959482860590467161609552169396182763685292434699999"), + expectedY: utils.StrToBig("3154881600662997558972388646773898448430820936643060392452233533274798056266"), }, } diff --git a/examples/curve/main.go b/examples/curve/main.go index 3a66e194..a130f28c 100644 --- a/examples/curve/main.go +++ b/examples/curve/main.go @@ -5,7 +5,7 @@ import ( "math/big" starknetgo "github.com/NethermindEth/starknet.go" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) func main() { @@ -15,7 +15,7 @@ func main() { It is recommended to use in the same way(i.e. `curve.Sign` and not `ecdsa.Sign`). NOTE: when not given local file path this pulls the curve data from Starkware github repo */ - hash, err := starknetgo.Curve.PedersenHash([]*big.Int{types.HexToBN("0x12773"), types.HexToBN("0x872362")}) + hash, err := starknetgo.Curve.PedersenHash([]*big.Int{utils.HexToBN("0x12773"), utils.HexToBN("0x872362")}) if err != nil { panic(err.Error()) } diff --git a/examples/simpleCall/main.go b/examples/simpleCall/main.go index 81900182..b92e09f4 100644 --- a/examples/simpleCall/main.go +++ b/examples/simpleCall/main.go @@ -6,7 +6,6 @@ import ( "os" "github.com/NethermindEth/starknet.go/rpc" - "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" ethrpc "github.com/ethereum/go-ethereum/rpc" "github.com/joho/godotenv" @@ -38,7 +37,7 @@ func main() { // Make read contract call tx := rpc.FunctionCall{ ContractAddress: contractAddress, - EntryPointSelector: types.GetSelectorFromNameFelt(contractMethod), + EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), } fmt.Println("Making Call() request") diff --git a/rpc/call_test.go b/rpc/call_test.go index 8f22e12e..79180384 100644 --- a/rpc/call_test.go +++ b/rpc/call_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" "github.com/test-go/testify/require" ) @@ -25,7 +24,7 @@ func TestCall(t *testing.T) { FunctionCall: FunctionCall{ // ContractAddress of predeployed devnet Feetoken ContractAddress: utils.TestHexToFelt(t, "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), - EntryPointSelector: types.GetSelectorFromNameFelt("name"), + EntryPointSelector: utils.GetSelectorFromNameFelt("name"), Calldata: []*felt.Felt{}, }, BlockID: WithBlockTag("latest"), @@ -36,7 +35,7 @@ func TestCall(t *testing.T) { { FunctionCall: FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0xdeadbeef"), - EntryPointSelector: types.GetSelectorFromNameFelt("decimals"), + EntryPointSelector: utils.GetSelectorFromNameFelt("decimals"), Calldata: []*felt.Felt{}, }, BlockID: WithBlockTag("latest"), @@ -58,7 +57,7 @@ func TestCall(t *testing.T) { { FunctionCall: FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x06a09ccb1caaecf3d9683efe335a667b2169a409d19c589ba1eb771cd210af75"), - EntryPointSelector: types.GetSelectorFromNameFelt("decimals"), + EntryPointSelector: utils.GetSelectorFromNameFelt("decimals"), Calldata: []*felt.Felt{}, }, BlockID: WithBlockTag("latest"), diff --git a/rpc/chain.go b/rpc/chain.go index 9747d30b..b36c32df 100644 --- a/rpc/chain.go +++ b/rpc/chain.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) // ChainID retrieves the current chain ID for transaction replay protection. @@ -17,7 +17,7 @@ func (provider *Provider) ChainID(ctx context.Context) (string, error) { if err := provider.c.CallContext(ctx, &result, "starknet_chainId", []interface{}{}...); err != nil { return "", err } - provider.chainID = types.HexToShortStr(result) + provider.chainID = utils.HexToShortStr(result) return provider.chainID, nil } diff --git a/rpc/contract.go b/rpc/contract.go index 57710938..940c550a 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -7,7 +7,7 @@ import ( "fmt" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) // Class gets the contract class definition associated with the given hash. @@ -83,7 +83,7 @@ func (provider *Provider) ClassHashAt(ctx context.Context, blockID BlockID, cont // StorageAt gets the value of the storage at the given address and key. func (provider *Provider) StorageAt(ctx context.Context, contractAddress *felt.Felt, key string, blockID BlockID) (string, error) { var value string - hashKey := fmt.Sprintf("0x%x", types.GetSelectorFromName(key)) + hashKey := fmt.Sprintf("0x%x", utils.GetSelectorFromName(key)) if err := do(ctx, provider.c, "starknet_getStorageAt", &value, contractAddress, hashKey, blockID); err != nil { switch { case errors.Is(err, ErrContractNotFound): diff --git a/rpc/types.go b/rpc/types.go index a30696e2..07eafd67 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -136,11 +136,11 @@ func (s *SyncStatus) UnmarshalJSON(data []byte) error { // return err // } // s.StartingBlockHash = output["starting_block_hash"].(string) - // s.StartingBlockNum = types.NumAsHex(output["starting_block_num"].(string)) + // s.StartingBlockNum = utils.NumAsHex(output["starting_block_num"].(string)) // s.CurrentBlockHash = output["current_block_hash"].(string) - // s.CurrentBlockNum = types.NumAsHex(output["current_block_num"].(string)) + // s.CurrentBlockNum = utils.NumAsHex(output["current_block_num"].(string)) // s.HighestBlockHash = output["highest_block_hash"].(string) - // s.HighestBlockNum = types.NumAsHex(output["highest_block_num"].(string)) + // s.HighestBlockNum = utils.NumAsHex(output["highest_block_num"].(string)) // return nil } diff --git a/starknetgo_test.go b/starknetgo_test.go index 420fbeef..bcb1546b 100644 --- a/starknetgo_test.go +++ b/starknetgo_test.go @@ -6,7 +6,7 @@ import ( "math/big" "testing" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) func BenchmarkSignatureVerify(b *testing.B) { @@ -15,8 +15,8 @@ func BenchmarkSignatureVerify(b *testing.B) { hash, _ := Curve.PedersenHash( []*big.Int{ - types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), - types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde"), + utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), + utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbdde"), }) r, s, _ := Curve.Sign(hash, private) @@ -31,7 +31,7 @@ func BenchmarkSignatureVerify(b *testing.B) { func TestGeneral_ComputeHashOnElements(t *testing.T) { hashEmptyArray, err := Curve.ComputeHashOnElements([]*big.Int{}) - expectedHashEmmptyArray := types.HexToBN("0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804") + expectedHashEmmptyArray := utils.HexToBN("0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804") if err != nil { t.Errorf("Could no hash an empty array %v\n", err) } @@ -44,7 +44,7 @@ func TestGeneral_ComputeHashOnElements(t *testing.T) { big.NewInt(213984), big.NewInt(128763521321), }) - expectedHashFilledArray := types.HexToBN("0x7b422405da6571242dfc245a43de3b0fe695e7021c148b918cd9cdb462cac59") + expectedHashFilledArray := utils.HexToBN("0x7b422405da6571242dfc245a43de3b0fe695e7021c148b918cd9cdb462cac59") if err != nil { t.Errorf("Could no hash an array with values %v\n", err) @@ -87,19 +87,19 @@ func TestGeneral_ComputeFact(t *testing.T) { expected *big.Int }{ { - programHash: types.HexToBN("0x114952172aed91e59f870a314e75de0a437ff550e4618068cec2d832e48b0c7"), + programHash: utils.HexToBN("0x114952172aed91e59f870a314e75de0a437ff550e4618068cec2d832e48b0c7"), programOutput: []*big.Int{big.NewInt(289)}, - expected: types.HexToBN("0xe6168c0a865aa80d724ad05627fa65fbcfe4b1d66a586e9f348f461b076072c4"), + expected: utils.HexToBN("0xe6168c0a865aa80d724ad05627fa65fbcfe4b1d66a586e9f348f461b076072c4"), }, { - programHash: types.HexToBN("0x79920d895101ad1fbdea9adf141d8f362fdea9ee35f33dfcd07f38e4a589bab"), - programOutput: []*big.Int{types.StrToBig("2754806153357301156380357983574496185342034785016738734224771556919270737441")}, - expected: types.HexToBN("0x1d174fa1443deea9aab54bbca8d9be308dd14a0323dd827556c173bd132098db"), + programHash: utils.HexToBN("0x79920d895101ad1fbdea9adf141d8f362fdea9ee35f33dfcd07f38e4a589bab"), + programOutput: []*big.Int{utils.StrToBig("2754806153357301156380357983574496185342034785016738734224771556919270737441")}, + expected: utils.HexToBN("0x1d174fa1443deea9aab54bbca8d9be308dd14a0323dd827556c173bd132098db"), }, } for _, tt := range testFacts { - hash := types.ComputeFact(tt.programHash, tt.programOutput) + hash := utils.ComputeFact(tt.programHash, tt.programOutput) if hash.Cmp(tt.expected) != 0 { t.Errorf("Fact does not equal ex %v %v\n", hash, tt.expected) } @@ -107,7 +107,7 @@ func TestGeneral_ComputeFact(t *testing.T) { } func TestGeneral_BadSignature(t *testing.T) { - hash, err := Curve.PedersenHash([]*big.Int{types.HexToBN("0x12773"), types.HexToBN("0x872362")}) + hash, err := Curve.PedersenHash([]*big.Int{utils.HexToBN("0x12773"), utils.HexToBN("0x872362")}) if err != nil { t.Errorf("Hashing err: %v\n", err) } @@ -150,31 +150,31 @@ func TestGeneral_Signature(t *testing.T) { raw string }{ { - private: types.StrToBig("104397037759416840641267745129360920341912682966983343798870479003077644689"), - publicX: types.StrToBig("1913222325711601599563860015182907040361852177892954047964358042507353067365"), - publicY: types.StrToBig("798905265292544287704154888908626830160713383708400542998012716235575472365"), - hash: types.StrToBig("2680576269831035412725132645807649347045997097070150916157159360688041452746"), - rIn: types.StrToBig("607684330780324271206686790958794501662789535258258105407533051445036595885"), - sIn: types.StrToBig("453590782387078613313238308551260565642934039343903827708036287031471258875"), + private: utils.StrToBig("104397037759416840641267745129360920341912682966983343798870479003077644689"), + publicX: utils.StrToBig("1913222325711601599563860015182907040361852177892954047964358042507353067365"), + publicY: utils.StrToBig("798905265292544287704154888908626830160713383708400542998012716235575472365"), + hash: utils.StrToBig("2680576269831035412725132645807649347045997097070150916157159360688041452746"), + rIn: utils.StrToBig("607684330780324271206686790958794501662789535258258105407533051445036595885"), + sIn: utils.StrToBig("453590782387078613313238308551260565642934039343903827708036287031471258875"), }, { - hash: types.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), - rIn: types.StrToBig("2458502865976494910213617956670505342647705497324144349552978333078363662855"), - sIn: types.StrToBig("3439514492576562277095748549117516048613512930236865921315982886313695689433"), + hash: utils.HexToBN("0x7f15c38ea577a26f4f553282fcfe4f1feeb8ecfaad8f221ae41abf8224cbddd"), + rIn: utils.StrToBig("2458502865976494910213617956670505342647705497324144349552978333078363662855"), + sIn: utils.StrToBig("3439514492576562277095748549117516048613512930236865921315982886313695689433"), raw: "04033f45f07e1bd1a51b45fc24ec8c8c9908db9e42191be9e169bfcac0c0d997450319d0f53f6ca077c4fa5207819144a2a4165daef6ee47a7c1d06c0dcaa3e456", }, { - hash: types.HexToBN("0x324df642fcc7d98b1d9941250840704f35b9ac2e3e2b58b6a034cc09adac54c"), - publicX: types.HexToBN("0x4e52f2f40700e9cdd0f386c31a1f160d0f310504fc508a1051b747a26070d10"), - rIn: types.StrToBig("2849277527182985104629156126825776904262411756563556603659114084811678482647"), - sIn: types.StrToBig("3156340738553451171391693475354397094160428600037567299774561739201502791079"), + hash: utils.HexToBN("0x324df642fcc7d98b1d9941250840704f35b9ac2e3e2b58b6a034cc09adac54c"), + publicX: utils.HexToBN("0x4e52f2f40700e9cdd0f386c31a1f160d0f310504fc508a1051b747a26070d10"), + rIn: utils.StrToBig("2849277527182985104629156126825776904262411756563556603659114084811678482647"), + sIn: utils.StrToBig("3156340738553451171391693475354397094160428600037567299774561739201502791079"), }, } var err error for _, tt := range testSignature { if tt.raw != "" { - h, _ := types.HexToBytes(tt.raw) + h, _ := utils.HexToBytes(tt.raw) tt.publicX, tt.publicY = elliptic.Unmarshal(Curve, h) } else if tt.private != nil { tt.publicX, tt.publicY, err = Curve.PrivateToPoint(tt.private) diff --git a/typed.go b/typed.go index cc6e913a..90364847 100644 --- a/typed.go +++ b/typed.go @@ -8,7 +8,7 @@ import ( "regexp" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) type TypedData struct { @@ -113,7 +113,7 @@ func NewTypedData(types map[string]TypeDef, pType string, dom Domain) (td TypedD // (ref: https://github.com/0xs34n/starknet.js/blob/767021a203ac0b9cdb282eb6d63b33bfd7614858/src/utils/typedData/index.ts#L166) func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage, sc StarkCurve) (hash *big.Int, err error) { - elements := []*big.Int{types.UTF8StrToBig("Starknet Message")} + elements := []*big.Int{utils.UTF8StrToBig("Starknet Message")} domEnc, err := td.GetTypedMessageHash("StarknetDomain", td.Domain, sc) if err != nil { @@ -166,7 +166,7 @@ func (td TypedData) GetTypeHash(inType string) (ret *big.Int, err error) { if err != nil { return ret, err } - sel := types.GetSelectorFromName(enc) + sel := utils.GetSelectorFromName(enc) return sel, nil } diff --git a/typed_test.go b/typed_test.go index 30e73dcd..63b008db 100644 --- a/typed_test.go +++ b/typed_test.go @@ -5,7 +5,7 @@ import ( "math/big" "testing" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) type Mail struct { @@ -21,13 +21,13 @@ type Person struct { func (mail Mail) FmtDefinitionEncoding(field string) (fmtEnc []*big.Int) { if field == "from" { - fmtEnc = append(fmtEnc, types.UTF8StrToBig(mail.From.Name)) - fmtEnc = append(fmtEnc, types.HexToBN(mail.From.Wallet)) + fmtEnc = append(fmtEnc, utils.UTF8StrToBig(mail.From.Name)) + fmtEnc = append(fmtEnc, utils.HexToBN(mail.From.Wallet)) } else if field == "to" { - fmtEnc = append(fmtEnc, types.UTF8StrToBig(mail.To.Name)) - fmtEnc = append(fmtEnc, types.HexToBN(mail.To.Wallet)) + fmtEnc = append(fmtEnc, utils.UTF8StrToBig(mail.To.Name)) + fmtEnc = append(fmtEnc, utils.HexToBN(mail.To.Wallet)) } else if field == "contents" { - fmtEnc = append(fmtEnc, types.UTF8StrToBig(mail.Contents)) + fmtEnc = append(fmtEnc, utils.UTF8StrToBig(mail.Contents)) } return fmtEnc } @@ -66,14 +66,14 @@ func TestGeneral_GetMessageHash(t *testing.T) { Contents: "Hello, Bob!", } - hash, err := ttd.GetMessageHash(types.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), mail, Curve) + hash, err := ttd.GetMessageHash(utils.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"), mail, Curve) if err != nil { t.Errorf("Could not hash message: %v\n", err) } exp := "0x6fcff244f63e38b9d88b9e3378d44757710d1b244282b435cb472053c8d78d0" - if types.BigToHex(hash) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(hash) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } } @@ -91,7 +91,7 @@ func BenchmarkGetMessageHash(b *testing.B) { }, Contents: "Hello, Bob!", } - addr := types.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826") + addr := utils.HexToBN("0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826") b.Run(fmt.Sprintf("input_size_%d", addr.BitLen()), func(b *testing.B) { ttd.GetMessageHash(addr, mail, Curve) }) @@ -106,8 +106,8 @@ func TestGeneral_GetDomainHash(t *testing.T) { } exp := "0x54833b121883a3e3aebff48ec08a962f5742e5f7b973469c1f8f4f55d470b07" - if types.BigToHex(hash) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(hash) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } } @@ -133,8 +133,8 @@ func TestGeneral_GetTypedMessageHash(t *testing.T) { } exp := "0x4758f1ed5e7503120c228cbcaba626f61514559e9ef5ed653b0b885e0f38aec" - if types.BigToHex(hash) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(hash) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } } @@ -147,13 +147,13 @@ func TestGeneral_GetTypeHash(t *testing.T) { } exp := "0x1bfc207425a47a5dfa1a50a4f5241203f50624ca5fdf5e18755765416b8e288" - if types.BigToHex(hash) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(hash) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } enc := tdd.Types["StarknetDomain"] - if types.BigToHex(enc.Encoding) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(enc.Encoding) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } pHash, err := tdd.GetTypeHash("Person") @@ -162,20 +162,20 @@ func TestGeneral_GetTypeHash(t *testing.T) { } exp = "0x2896dbe4b96a67110f454c01e5336edc5bbc3635537efd690f122f4809cc855" - if types.BigToHex(pHash) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(pHash), exp) + if utils.BigToHex(pHash) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(pHash), exp) } enc = tdd.Types["Person"] - if types.BigToHex(enc.Encoding) != exp { - t.Errorf("type hash: %v does not match expected %v\n", types.BigToHex(hash), exp) + if utils.BigToHex(enc.Encoding) != exp { + t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp) } } func TestGeneral_GetSelectorFromName(t *testing.T) { - sel1 := types.BigToHex(types.GetSelectorFromName("initialize")) - sel2 := types.BigToHex(types.GetSelectorFromName("mint")) - sel3 := types.BigToHex(types.GetSelectorFromName("test")) + sel1 := utils.BigToHex(utils.GetSelectorFromName("initialize")) + sel2 := utils.BigToHex(utils.GetSelectorFromName("mint")) + sel3 := utils.BigToHex(utils.GetSelectorFromName("test")) exp1 := "0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463" exp2 := "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354" diff --git a/types/testdata/cairo/invalid_minimum_contract_compiled.json b/types/testdata/cairo/invalid_minimum_contract_compiled.json deleted file mode 100644 index aca5f190..00000000 --- a/types/testdata/cairo/invalid_minimum_contract_compiled.json +++ /dev/null @@ -1,885 +0,0 @@ -{ - "abi": {}, - "entry_points_by_type": { - "CONSTRUCTOR": [], - "EXTERNAL": [], - "L1_HANDLER": [] - }, - "program": { - "attributes": [], - "builtins": [ - "range_check" - ], - "compiler_version": "0.10.0", - "data": [], - "debug_info": null, - "hints": {}, - "identifiers": { - "starkware.cairo.common.bool.FALSE": { - "type": "const", - "value": 0 - }, - "starkware.cairo.common.bool.TRUE": { - "type": "const", - "value": 1 - }, - "starkware.cairo.common.cairo_builtins.BitwiseBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.BitwiseBuiltin", - "members": { - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "x_and_y": { - "cairo_type": "felt", - "offset": 2 - }, - "x_or_y": { - "cairo_type": "felt", - "offset": 4 - }, - "x_xor_y": { - "cairo_type": "felt", - "offset": 3 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.EcOpBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.EcOpBuiltin", - "members": { - "m": { - "cairo_type": "felt", - "offset": 4 - }, - "p": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 0 - }, - "q": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 2 - }, - "r": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.EcPoint": { - "destination": "starkware.cairo.common.ec_point.EcPoint", - "type": "alias" - }, - "starkware.cairo.common.cairo_builtins.HashBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.HashBuiltin", - "members": { - "result": { - "cairo_type": "felt", - "offset": 2 - }, - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.KeccakBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.KeccakBuiltin", - "members": { - "input": { - "cairo_type": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "offset": 0 - }, - "output": { - "cairo_type": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "offset": 8 - } - }, - "size": 16, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.KeccakBuiltinState": { - "destination": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "type": "alias" - }, - "starkware.cairo.common.cairo_builtins.SignatureBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.SignatureBuiltin", - "members": { - "message": { - "cairo_type": "felt", - "offset": 1 - }, - "pub_key": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.cairo.common.dict_access.DictAccess": { - "full_name": "starkware.cairo.common.dict_access.DictAccess", - "members": { - "key": { - "cairo_type": "felt", - "offset": 0 - }, - "new_value": { - "cairo_type": "felt", - "offset": 2 - }, - "prev_value": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.cairo.common.ec_point.EcPoint": { - "full_name": "starkware.cairo.common.ec_point.EcPoint", - "members": { - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.cairo.common.hash.HashBuiltin": { - "destination": "starkware.cairo.common.cairo_builtins.HashBuiltin", - "type": "alias" - }, - "starkware.cairo.common.keccak_state.KeccakBuiltinState": { - "full_name": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "members": { - "s0": { - "cairo_type": "felt", - "offset": 0 - }, - "s1": { - "cairo_type": "felt", - "offset": 1 - }, - "s2": { - "cairo_type": "felt", - "offset": 2 - }, - "s3": { - "cairo_type": "felt", - "offset": 3 - }, - "s4": { - "cairo_type": "felt", - "offset": 4 - }, - "s5": { - "cairo_type": "felt", - "offset": 5 - }, - "s6": { - "cairo_type": "felt", - "offset": 6 - }, - "s7": { - "cairo_type": "felt", - "offset": 7 - } - }, - "size": 8, - "type": "struct" - }, - "starkware.cairo.common.math.FALSE": { - "destination": "starkware.cairo.common.bool.FALSE", - "type": "alias" - }, - "starkware.cairo.common.math.TRUE": { - "destination": "starkware.cairo.common.bool.TRUE", - "type": "alias" - }, - "starkware.starknet.common.storage.ADDR_BOUND": { - "type": "const", - "value": -106710729501573572985208420194530329073740042555888586719489 - }, - "starkware.starknet.common.storage.MAX_STORAGE_ITEM_SIZE": { - "type": "const", - "value": 256 - }, - "starkware.starknet.common.storage.assert_250_bit": { - "destination": "starkware.cairo.common.math.assert_250_bit", - "type": "alias" - }, - "starkware.starknet.common.syscalls.CALL_CONTRACT_SELECTOR": { - "type": "const", - "value": 20853273475220472486191784820 - }, - "starkware.starknet.common.syscalls.CallContract": { - "full_name": "starkware.starknet.common.syscalls.CallContract", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractResponse", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.starknet.common.syscalls.CallContractRequest": { - "full_name": "starkware.starknet.common.syscalls.CallContractRequest", - "members": { - "calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "contract_address": { - "cairo_type": "felt", - "offset": 1 - }, - "function_selector": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.CallContractResponse": { - "full_name": "starkware.starknet.common.syscalls.CallContractResponse", - "members": { - "retdata": { - "cairo_type": "felt*", - "offset": 1 - }, - "retdata_size": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DELEGATE_CALL_SELECTOR": { - "type": "const", - "value": 21167594061783206823196716140 - }, - "starkware.starknet.common.syscalls.DELEGATE_L1_HANDLER_SELECTOR": { - "type": "const", - "value": 23274015802972845247556842986379118667122 - }, - "starkware.starknet.common.syscalls.DEPLOY_SELECTOR": { - "type": "const", - "value": 75202468540281 - }, - "starkware.starknet.common.syscalls.Deploy": { - "full_name": "starkware.starknet.common.syscalls.Deploy", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.DeployRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.DeployResponse", - "offset": 6 - } - }, - "size": 9, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DeployRequest": { - "full_name": "starkware.starknet.common.syscalls.DeployRequest", - "members": { - "class_hash": { - "cairo_type": "felt", - "offset": 1 - }, - "constructor_calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "constructor_calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "contract_address_salt": { - "cairo_type": "felt", - "offset": 2 - }, - "deploy_from_zero": { - "cairo_type": "felt", - "offset": 5 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 6, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DeployResponse": { - "full_name": "starkware.starknet.common.syscalls.DeployResponse", - "members": { - "constructor_retdata": { - "cairo_type": "felt*", - "offset": 2 - }, - "constructor_retdata_size": { - "cairo_type": "felt", - "offset": 1 - }, - "contract_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DictAccess": { - "destination": "starkware.cairo.common.dict_access.DictAccess", - "type": "alias" - }, - "starkware.starknet.common.syscalls.EMIT_EVENT_SELECTOR": { - "type": "const", - "value": 1280709301550335749748 - }, - "starkware.starknet.common.syscalls.EmitEvent": { - "full_name": "starkware.starknet.common.syscalls.EmitEvent", - "members": { - "data": { - "cairo_type": "felt*", - "offset": 4 - }, - "data_len": { - "cairo_type": "felt", - "offset": 3 - }, - "keys": { - "cairo_type": "felt*", - "offset": 2 - }, - "keys_len": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GET_BLOCK_NUMBER_SELECTOR": { - "type": "const", - "value": 1448089106835523001438702345020786 - }, - "starkware.starknet.common.syscalls.GET_BLOCK_TIMESTAMP_SELECTOR": { - "type": "const", - "value": 24294903732626645868215235778792757751152 - }, - "starkware.starknet.common.syscalls.GET_CALLER_ADDRESS_SELECTOR": { - "type": "const", - "value": 94901967781393078444254803017658102643 - }, - "starkware.starknet.common.syscalls.GET_CONTRACT_ADDRESS_SELECTOR": { - "type": "const", - "value": 6219495360805491471215297013070624192820083 - }, - "starkware.starknet.common.syscalls.GET_SEQUENCER_ADDRESS_SELECTOR": { - "type": "const", - "value": 1592190833581991703053805829594610833820054387 - }, - "starkware.starknet.common.syscalls.GET_TX_INFO_SELECTOR": { - "type": "const", - "value": 1317029390204112103023 - }, - "starkware.starknet.common.syscalls.GET_TX_SIGNATURE_SELECTOR": { - "type": "const", - "value": 1448089128652340074717162277007973 - }, - "starkware.starknet.common.syscalls.GetBlockNumber": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumber", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockNumberRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockNumberResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockNumberRequest": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumberRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockNumberResponse": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumberResponse", - "members": { - "block_number": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestamp": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestamp", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockTimestampRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockTimestampResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestampRequest": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestampRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestampResponse": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestampResponse", - "members": { - "block_timestamp": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddress": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetCallerAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetCallerAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddressResponse", - "members": { - "caller_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddress": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetContractAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetContractAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddressResponse", - "members": { - "contract_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddress": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetSequencerAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetSequencerAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddressResponse", - "members": { - "sequencer_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfo": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfo", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxInfoRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxInfoResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfoRequest": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfoRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfoResponse": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfoResponse", - "members": { - "tx_info": { - "cairo_type": "starkware.starknet.common.syscalls.TxInfo*", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignature": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignature", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxSignatureRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxSignatureResponse", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignatureRequest": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignatureRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignatureResponse": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignatureResponse", - "members": { - "signature": { - "cairo_type": "felt*", - "offset": 1 - }, - "signature_len": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.LIBRARY_CALL_L1_HANDLER_SELECTOR": { - "type": "const", - "value": 436233452754198157705746250789557519228244616562 - }, - "starkware.starknet.common.syscalls.LIBRARY_CALL_SELECTOR": { - "type": "const", - "value": 92376026794327011772951660 - }, - "starkware.starknet.common.syscalls.LibraryCall": { - "full_name": "starkware.starknet.common.syscalls.LibraryCall", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.LibraryCallRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractResponse", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.starknet.common.syscalls.LibraryCallRequest": { - "full_name": "starkware.starknet.common.syscalls.LibraryCallRequest", - "members": { - "calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "class_hash": { - "cairo_type": "felt", - "offset": 1 - }, - "function_selector": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.SEND_MESSAGE_TO_L1_SELECTOR": { - "type": "const", - "value": 433017908768303439907196859243777073 - }, - "starkware.starknet.common.syscalls.STORAGE_READ_SELECTOR": { - "type": "const", - "value": 100890693370601760042082660 - }, - "starkware.starknet.common.syscalls.STORAGE_WRITE_SELECTOR": { - "type": "const", - "value": 25828017502874050592466629733 - }, - "starkware.starknet.common.syscalls.SendMessageToL1SysCall": { - "full_name": "starkware.starknet.common.syscalls.SendMessageToL1SysCall", - "members": { - "payload_ptr": { - "cairo_type": "felt*", - "offset": 3 - }, - "payload_size": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - }, - "to_address": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 4, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageRead": { - "full_name": "starkware.starknet.common.syscalls.StorageRead", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.StorageReadRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.StorageReadResponse", - "offset": 2 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageReadRequest": { - "full_name": "starkware.starknet.common.syscalls.StorageReadRequest", - "members": { - "address": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageReadResponse": { - "full_name": "starkware.starknet.common.syscalls.StorageReadResponse", - "members": { - "value": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageWrite": { - "full_name": "starkware.starknet.common.syscalls.StorageWrite", - "members": { - "address": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - }, - "value": { - "cairo_type": "felt", - "offset": 2 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.TxInfo": { - "full_name": "starkware.starknet.common.syscalls.TxInfo", - "members": { - "account_contract_address": { - "cairo_type": "felt", - "offset": 1 - }, - "chain_id": { - "cairo_type": "felt", - "offset": 6 - }, - "max_fee": { - "cairo_type": "felt", - "offset": 2 - }, - "nonce": { - "cairo_type": "felt", - "offset": 7 - }, - "signature": { - "cairo_type": "felt*", - "offset": 4 - }, - "signature_len": { - "cairo_type": "felt", - "offset": 3 - }, - "transaction_hash": { - "cairo_type": "felt", - "offset": 5 - }, - "version": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 8, - "type": "struct" - } - }, - "main_scope": "__main__", - "prime": "0x800000000000011000000000000000000000000000000000000000000000001", - "reference_manager": { - "references": [] - } - } -} \ No newline at end of file diff --git a/types/testdata/cairo/minimum_contract_compiled.json b/types/testdata/cairo/minimum_contract_compiled.json deleted file mode 100644 index 6bdaf69e..00000000 --- a/types/testdata/cairo/minimum_contract_compiled.json +++ /dev/null @@ -1,885 +0,0 @@ -{ - "abi": [], - "entry_points_by_type": { - "CONSTRUCTOR": [], - "EXTERNAL": [], - "L1_HANDLER": [] - }, - "program": { - "attributes": [], - "builtins": [ - "range_check" - ], - "compiler_version": "0.10.0", - "data": [], - "debug_info": null, - "hints": {}, - "identifiers": { - "starkware.cairo.common.bool.FALSE": { - "type": "const", - "value": 0 - }, - "starkware.cairo.common.bool.TRUE": { - "type": "const", - "value": 1 - }, - "starkware.cairo.common.cairo_builtins.BitwiseBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.BitwiseBuiltin", - "members": { - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "x_and_y": { - "cairo_type": "felt", - "offset": 2 - }, - "x_or_y": { - "cairo_type": "felt", - "offset": 4 - }, - "x_xor_y": { - "cairo_type": "felt", - "offset": 3 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.EcOpBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.EcOpBuiltin", - "members": { - "m": { - "cairo_type": "felt", - "offset": 4 - }, - "p": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 0 - }, - "q": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 2 - }, - "r": { - "cairo_type": "starkware.cairo.common.ec_point.EcPoint", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.EcPoint": { - "destination": "starkware.cairo.common.ec_point.EcPoint", - "type": "alias" - }, - "starkware.cairo.common.cairo_builtins.HashBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.HashBuiltin", - "members": { - "result": { - "cairo_type": "felt", - "offset": 2 - }, - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.KeccakBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.KeccakBuiltin", - "members": { - "input": { - "cairo_type": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "offset": 0 - }, - "output": { - "cairo_type": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "offset": 8 - } - }, - "size": 16, - "type": "struct" - }, - "starkware.cairo.common.cairo_builtins.KeccakBuiltinState": { - "destination": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "type": "alias" - }, - "starkware.cairo.common.cairo_builtins.SignatureBuiltin": { - "full_name": "starkware.cairo.common.cairo_builtins.SignatureBuiltin", - "members": { - "message": { - "cairo_type": "felt", - "offset": 1 - }, - "pub_key": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.cairo.common.dict_access.DictAccess": { - "full_name": "starkware.cairo.common.dict_access.DictAccess", - "members": { - "key": { - "cairo_type": "felt", - "offset": 0 - }, - "new_value": { - "cairo_type": "felt", - "offset": 2 - }, - "prev_value": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.cairo.common.ec_point.EcPoint": { - "full_name": "starkware.cairo.common.ec_point.EcPoint", - "members": { - "x": { - "cairo_type": "felt", - "offset": 0 - }, - "y": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.cairo.common.hash.HashBuiltin": { - "destination": "starkware.cairo.common.cairo_builtins.HashBuiltin", - "type": "alias" - }, - "starkware.cairo.common.keccak_state.KeccakBuiltinState": { - "full_name": "starkware.cairo.common.keccak_state.KeccakBuiltinState", - "members": { - "s0": { - "cairo_type": "felt", - "offset": 0 - }, - "s1": { - "cairo_type": "felt", - "offset": 1 - }, - "s2": { - "cairo_type": "felt", - "offset": 2 - }, - "s3": { - "cairo_type": "felt", - "offset": 3 - }, - "s4": { - "cairo_type": "felt", - "offset": 4 - }, - "s5": { - "cairo_type": "felt", - "offset": 5 - }, - "s6": { - "cairo_type": "felt", - "offset": 6 - }, - "s7": { - "cairo_type": "felt", - "offset": 7 - } - }, - "size": 8, - "type": "struct" - }, - "starkware.cairo.common.math.FALSE": { - "destination": "starkware.cairo.common.bool.FALSE", - "type": "alias" - }, - "starkware.cairo.common.math.TRUE": { - "destination": "starkware.cairo.common.bool.TRUE", - "type": "alias" - }, - "starkware.starknet.common.storage.ADDR_BOUND": { - "type": "const", - "value": -106710729501573572985208420194530329073740042555888586719489 - }, - "starkware.starknet.common.storage.MAX_STORAGE_ITEM_SIZE": { - "type": "const", - "value": 256 - }, - "starkware.starknet.common.storage.assert_250_bit": { - "destination": "starkware.cairo.common.math.assert_250_bit", - "type": "alias" - }, - "starkware.starknet.common.syscalls.CALL_CONTRACT_SELECTOR": { - "type": "const", - "value": 20853273475220472486191784820 - }, - "starkware.starknet.common.syscalls.CallContract": { - "full_name": "starkware.starknet.common.syscalls.CallContract", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractResponse", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.starknet.common.syscalls.CallContractRequest": { - "full_name": "starkware.starknet.common.syscalls.CallContractRequest", - "members": { - "calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "contract_address": { - "cairo_type": "felt", - "offset": 1 - }, - "function_selector": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.CallContractResponse": { - "full_name": "starkware.starknet.common.syscalls.CallContractResponse", - "members": { - "retdata": { - "cairo_type": "felt*", - "offset": 1 - }, - "retdata_size": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DELEGATE_CALL_SELECTOR": { - "type": "const", - "value": 21167594061783206823196716140 - }, - "starkware.starknet.common.syscalls.DELEGATE_L1_HANDLER_SELECTOR": { - "type": "const", - "value": 23274015802972845247556842986379118667122 - }, - "starkware.starknet.common.syscalls.DEPLOY_SELECTOR": { - "type": "const", - "value": 75202468540281 - }, - "starkware.starknet.common.syscalls.Deploy": { - "full_name": "starkware.starknet.common.syscalls.Deploy", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.DeployRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.DeployResponse", - "offset": 6 - } - }, - "size": 9, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DeployRequest": { - "full_name": "starkware.starknet.common.syscalls.DeployRequest", - "members": { - "class_hash": { - "cairo_type": "felt", - "offset": 1 - }, - "constructor_calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "constructor_calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "contract_address_salt": { - "cairo_type": "felt", - "offset": 2 - }, - "deploy_from_zero": { - "cairo_type": "felt", - "offset": 5 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 6, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DeployResponse": { - "full_name": "starkware.starknet.common.syscalls.DeployResponse", - "members": { - "constructor_retdata": { - "cairo_type": "felt*", - "offset": 2 - }, - "constructor_retdata_size": { - "cairo_type": "felt", - "offset": 1 - }, - "contract_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.DictAccess": { - "destination": "starkware.cairo.common.dict_access.DictAccess", - "type": "alias" - }, - "starkware.starknet.common.syscalls.EMIT_EVENT_SELECTOR": { - "type": "const", - "value": 1280709301550335749748 - }, - "starkware.starknet.common.syscalls.EmitEvent": { - "full_name": "starkware.starknet.common.syscalls.EmitEvent", - "members": { - "data": { - "cairo_type": "felt*", - "offset": 4 - }, - "data_len": { - "cairo_type": "felt", - "offset": 3 - }, - "keys": { - "cairo_type": "felt*", - "offset": 2 - }, - "keys_len": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GET_BLOCK_NUMBER_SELECTOR": { - "type": "const", - "value": 1448089106835523001438702345020786 - }, - "starkware.starknet.common.syscalls.GET_BLOCK_TIMESTAMP_SELECTOR": { - "type": "const", - "value": 24294903732626645868215235778792757751152 - }, - "starkware.starknet.common.syscalls.GET_CALLER_ADDRESS_SELECTOR": { - "type": "const", - "value": 94901967781393078444254803017658102643 - }, - "starkware.starknet.common.syscalls.GET_CONTRACT_ADDRESS_SELECTOR": { - "type": "const", - "value": 6219495360805491471215297013070624192820083 - }, - "starkware.starknet.common.syscalls.GET_SEQUENCER_ADDRESS_SELECTOR": { - "type": "const", - "value": 1592190833581991703053805829594610833820054387 - }, - "starkware.starknet.common.syscalls.GET_TX_INFO_SELECTOR": { - "type": "const", - "value": 1317029390204112103023 - }, - "starkware.starknet.common.syscalls.GET_TX_SIGNATURE_SELECTOR": { - "type": "const", - "value": 1448089128652340074717162277007973 - }, - "starkware.starknet.common.syscalls.GetBlockNumber": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumber", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockNumberRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockNumberResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockNumberRequest": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumberRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockNumberResponse": { - "full_name": "starkware.starknet.common.syscalls.GetBlockNumberResponse", - "members": { - "block_number": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestamp": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestamp", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockTimestampRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetBlockTimestampResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestampRequest": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestampRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetBlockTimestampResponse": { - "full_name": "starkware.starknet.common.syscalls.GetBlockTimestampResponse", - "members": { - "block_timestamp": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddress": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetCallerAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetCallerAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetCallerAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetCallerAddressResponse", - "members": { - "caller_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddress": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetContractAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetContractAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetContractAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetContractAddressResponse", - "members": { - "contract_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddress": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddress", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetSequencerAddressRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetSequencerAddressResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddressRequest": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddressRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetSequencerAddressResponse": { - "full_name": "starkware.starknet.common.syscalls.GetSequencerAddressResponse", - "members": { - "sequencer_address": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfo": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfo", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxInfoRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxInfoResponse", - "offset": 1 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfoRequest": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfoRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxInfoResponse": { - "full_name": "starkware.starknet.common.syscalls.GetTxInfoResponse", - "members": { - "tx_info": { - "cairo_type": "starkware.starknet.common.syscalls.TxInfo*", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignature": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignature", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxSignatureRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.GetTxSignatureResponse", - "offset": 1 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignatureRequest": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignatureRequest", - "members": { - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.GetTxSignatureResponse": { - "full_name": "starkware.starknet.common.syscalls.GetTxSignatureResponse", - "members": { - "signature": { - "cairo_type": "felt*", - "offset": 1 - }, - "signature_len": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.LIBRARY_CALL_L1_HANDLER_SELECTOR": { - "type": "const", - "value": 436233452754198157705746250789557519228244616562 - }, - "starkware.starknet.common.syscalls.LIBRARY_CALL_SELECTOR": { - "type": "const", - "value": 92376026794327011772951660 - }, - "starkware.starknet.common.syscalls.LibraryCall": { - "full_name": "starkware.starknet.common.syscalls.LibraryCall", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.LibraryCallRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.CallContractResponse", - "offset": 5 - } - }, - "size": 7, - "type": "struct" - }, - "starkware.starknet.common.syscalls.LibraryCallRequest": { - "full_name": "starkware.starknet.common.syscalls.LibraryCallRequest", - "members": { - "calldata": { - "cairo_type": "felt*", - "offset": 4 - }, - "calldata_size": { - "cairo_type": "felt", - "offset": 3 - }, - "class_hash": { - "cairo_type": "felt", - "offset": 1 - }, - "function_selector": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 5, - "type": "struct" - }, - "starkware.starknet.common.syscalls.SEND_MESSAGE_TO_L1_SELECTOR": { - "type": "const", - "value": 433017908768303439907196859243777073 - }, - "starkware.starknet.common.syscalls.STORAGE_READ_SELECTOR": { - "type": "const", - "value": 100890693370601760042082660 - }, - "starkware.starknet.common.syscalls.STORAGE_WRITE_SELECTOR": { - "type": "const", - "value": 25828017502874050592466629733 - }, - "starkware.starknet.common.syscalls.SendMessageToL1SysCall": { - "full_name": "starkware.starknet.common.syscalls.SendMessageToL1SysCall", - "members": { - "payload_ptr": { - "cairo_type": "felt*", - "offset": 3 - }, - "payload_size": { - "cairo_type": "felt", - "offset": 2 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - }, - "to_address": { - "cairo_type": "felt", - "offset": 1 - } - }, - "size": 4, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageRead": { - "full_name": "starkware.starknet.common.syscalls.StorageRead", - "members": { - "request": { - "cairo_type": "starkware.starknet.common.syscalls.StorageReadRequest", - "offset": 0 - }, - "response": { - "cairo_type": "starkware.starknet.common.syscalls.StorageReadResponse", - "offset": 2 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageReadRequest": { - "full_name": "starkware.starknet.common.syscalls.StorageReadRequest", - "members": { - "address": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 2, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageReadResponse": { - "full_name": "starkware.starknet.common.syscalls.StorageReadResponse", - "members": { - "value": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 1, - "type": "struct" - }, - "starkware.starknet.common.syscalls.StorageWrite": { - "full_name": "starkware.starknet.common.syscalls.StorageWrite", - "members": { - "address": { - "cairo_type": "felt", - "offset": 1 - }, - "selector": { - "cairo_type": "felt", - "offset": 0 - }, - "value": { - "cairo_type": "felt", - "offset": 2 - } - }, - "size": 3, - "type": "struct" - }, - "starkware.starknet.common.syscalls.TxInfo": { - "full_name": "starkware.starknet.common.syscalls.TxInfo", - "members": { - "account_contract_address": { - "cairo_type": "felt", - "offset": 1 - }, - "chain_id": { - "cairo_type": "felt", - "offset": 6 - }, - "max_fee": { - "cairo_type": "felt", - "offset": 2 - }, - "nonce": { - "cairo_type": "felt", - "offset": 7 - }, - "signature": { - "cairo_type": "felt*", - "offset": 4 - }, - "signature_len": { - "cairo_type": "felt", - "offset": 3 - }, - "transaction_hash": { - "cairo_type": "felt", - "offset": 5 - }, - "version": { - "cairo_type": "felt", - "offset": 0 - } - }, - "size": 8, - "type": "struct" - } - }, - "main_scope": "__main__", - "prime": "0x800000000000011000000000000000000000000000000000000000000000001", - "reference_manager": { - "references": [] - } - } -} \ No newline at end of file diff --git a/types/types.go b/types/types.go deleted file mode 100644 index cda53398..00000000 --- a/types/types.go +++ /dev/null @@ -1,149 +0,0 @@ -package types - -import ( - "fmt" - "math/big" - "strconv" - - "github.com/NethermindEth/juno/core/felt" -) - -type NumAsHex string - -type AddInvokeTransactionOutput struct { - TransactionHash *felt.Felt `json:"transaction_hash"` -} - -type AddDeclareResponse struct { - Code string `json:"code"` - TransactionHash string `json:"transaction_hash"` - ClassHash string `json:"class_hash"` -} - -type AddDeployResponse struct { - Code string `json:"code"` - TransactionHash string `json:"transaction_hash"` - ContractAddress string `json:"address"` -} - -// // TODO: remove -// type DeployRequest struct { -// Type string `json:"type"` -// ContractAddressSalt string `json:"contract_address_salt"` -// ConstructorCalldata []string `json:"constructor_calldata"` -// ContractDefinition rpc.ContractClass `json:"contract_definition"` -// } - -type DeployAccountRequest struct { - MaxFee *big.Int `json:"max_fee"` - // Version of the transaction scheme, should be set to 0 or 1 - Version *big.Int `json:"version"` - // Signature - Signature Signature `json:"signature"` - // Nonce should only be set with Transaction V1 - Nonce *big.Int `json:"nonce,omitempty"` - - Type string `json:"type"` - ContractAddressSalt string `json:"contract_address_salt"` - ConstructorCalldata []string `json:"constructor_calldata"` - ClassHash string `json:"class_hash"` -} - -// FunctionCall function call information -type FunctionCall struct { - ContractAddress *felt.Felt `json:"contract_address"` - EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"` - - // Calldata The parameters passed to the function - Calldata []*felt.Felt `json:"calldata"` -} - -type Signature []*big.Int - -// todo(): what is this used for? -type FunctionInvoke struct { - MaxFee *big.Int `json:"max_fee"` - // Version of the transaction scheme, should be set to 0 or 1 - Version *big.Int `json:"version"` - // Signature - Signature Signature `json:"signature"` - // Nonce should only be set with Transaction V1 - Nonce *big.Int `json:"nonce,omitempty"` - // Defines the transaction type to invoke - Type string `json:"type,omitempty"` - - SenderAddress *felt.Felt `json:"sender_address"` - EntryPointSelector string `json:"entry_point_selector,omitempty"` - - // Calldata The parameters passed to the function - Calldata []string `json:"calldata"` -} - -type FeeEstimate struct { - // GasConsumed the Ethereum gas cost of the transaction (see https://docs.starknet.io/docs/Fees/fee-mechanism for more info) - GasConsumed NumAsHex `json:"gas_consumed"` - - // GasPrice the gas price (in gwei) that was used in the cost estimation - GasPrice NumAsHex `json:"gas_price"` - - // OverallFee the estimated fee for the transaction (in gwei), product of gas_consumed and gas_price - OverallFee NumAsHex `json:"overall_fee"` -} - -// ExecuteDetails provides some details about the execution. -type ExecuteDetails struct { - MaxFee *big.Int - Nonce *big.Int -} - -type TransactionState string - -const ( - TransactionAcceptedOnL1 TransactionState = "ACCEPTED_ON_L1" - TransactionAcceptedOnL2 TransactionState = "ACCEPTED_ON_L2" - TransactionNotReceived TransactionState = "NOT_RECEIVED" - TransactionPending TransactionState = "PENDING" - TransactionReceived TransactionState = "RECEIVED" - TransactionRejected TransactionState = "REJECTED" -) - -func (ts *TransactionState) UnmarshalJSON(data []byte) error { - unquoted, err := strconv.Unquote(string(data)) - if err != nil { - return err - } - switch unquoted { - case "ACCEPTED_ON_L2": - *ts = TransactionAcceptedOnL2 - case "ACCEPTED_ON_L1": - *ts = TransactionAcceptedOnL1 - case "NOT_RECEIVED": - *ts = TransactionNotReceived - case "PENDING": - *ts = TransactionPending - case "RECEIVED": - *ts = TransactionReceived - case "REJECTED": - *ts = TransactionRejected - default: - return fmt.Errorf("unsupported status: %s", data) - } - return nil -} - -func (ts TransactionState) MarshalJSON() ([]byte, error) { - return []byte(strconv.Quote(string(ts))), nil -} - -func (s TransactionState) String() string { - return string(s) -} - -func (s TransactionState) IsTransactionFinal() bool { - if s == TransactionAcceptedOnL2 || - s == TransactionAcceptedOnL1 || - s == TransactionRejected { - return true - } - return false -} diff --git a/types/types_test.go b/types/types_test.go deleted file mode 100644 index b6d26c95..00000000 --- a/types/types_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package types - -import ( - "encoding/json" - "testing" -) - -func TestTransactionStatus(t *testing.T) { - for _, tc := range []struct { - status string - want TransactionState - }{{ - status: `"PENDING"`, - want: TransactionPending, - }, { - status: `"ACCEPTED_ON_L2"`, - want: TransactionAcceptedOnL2, - }, { - status: `"ACCEPTED_ON_L1"`, - want: TransactionAcceptedOnL1, - }, { - status: `"REJECTED"`, - want: TransactionRejected, - }} { - var tx TransactionState - if err := json.Unmarshal([]byte(tc.status), &tx); err != nil { - t.Fatalf("unmarshalling status want: %s", err) - } - if tx != tc.want { - t.Fatalf("status error want %s, got %s", tc.want, tx) - } - } -} diff --git a/types/utils_test.go b/types/utils_test.go deleted file mode 100644 index e1666208..00000000 --- a/types/utils_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package types - -import ( - "testing" -) - -func TestSplitFactStr(t *testing.T) { - data := []map[string]string{ - {"input": "0x3", "h": "0x0", "l": "0x3"}, - {"input": "0x300000000000000000000000000000000", "h": "0x3", "l": "0x0"}, - } - for _, d := range data { - l, h := SplitFactStr(d["input"]) // 0x3 - if l != d["l"] { - t.Errorf("expected %s, got %s", d["l"], l) - } - if h != d["h"] { - t.Errorf("expected %s, got %s", d["h"], h) - } - } -} diff --git a/types/utils.go b/utils/keccak.go similarity index 98% rename from types/utils.go rename to utils/keccak.go index a4728cd7..3065b99e 100644 --- a/types/utils.go +++ b/utils/keccak.go @@ -1,4 +1,4 @@ -package types +package utils import ( "bytes" @@ -20,7 +20,7 @@ type KeccakState interface { Read([]byte) (int, error) } -// convert utf8 string to big int +// Convert utf8 string to big int func UTF8StrToBig(str string) *big.Int { hexStr := hex.EncodeToString([]byte(str)) b, _ := new(big.Int).SetString(hexStr, 16) diff --git a/utils_test.go b/utils_test.go index 8350b197..efce2c52 100644 --- a/utils_test.go +++ b/utils_test.go @@ -3,7 +3,7 @@ package starknetgo import ( "testing" - "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" ) func TestGeneral_SplitFactStr(t *testing.T) { @@ -12,7 +12,7 @@ func TestGeneral_SplitFactStr(t *testing.T) { {"input": "0x300000000000000000000000000000000", "h": "0x3", "l": "0x0"}, } for _, d := range data { - l, h := types.SplitFactStr(d["input"]) // 0x3 + l, h := utils.SplitFactStr(d["input"]) // 0x3 if l != d["l"] { t.Errorf("expected %s, got %s", d["l"], l) }