Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove types pkg #384

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"}),
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
8 changes: 4 additions & 4 deletions artifacts/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/NethermindEth/starknet.go/types"
"github.com/NethermindEth/starknet.go/utils"
)

//go:embed account.json
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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")
Expand All @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package contracts
import (
"context"
"fmt"

// "math/big"
"testing"
"time"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
// }
Expand Down
56 changes: 28 additions & 28 deletions curve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
},
}

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions examples/curve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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())
}
Expand Down
3 changes: 1 addition & 2 deletions examples/simpleCall/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions rpc/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions rpc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/types_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BlockHashAndNumberOutput struct {
}

// BlockID is a struct that is used to choose between different
// search types.
// search utils.
cicr99 marked this conversation as resolved.
Show resolved Hide resolved
type BlockID struct {
Number *uint64 `json:"block_number,omitempty"`
Hash *felt.Felt `json:"block_hash,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func unmarshalTransactionReceipt(t interface{}) (TransactionReceipt, error) {
switch casted := t.(type) {
case map[string]interface{}:
// NOTE(tvanas): Pathfinder 0.3.3 does not return
// transaction receipt types. We handle this by
// transaction receipt utils. We handle this by
cicr99 marked this conversation as resolved.
Show resolved Hide resolved
// naively marshalling into an invoke type. Once it
// is supported, this condition can be removed.
typ, ok := casted["type"]
Expand Down
Loading
Loading