Skip to content

Commit

Permalink
best guesses at feeder types
Browse files Browse the repository at this point in the history
  • Loading branch information
joshklop committed Nov 15, 2023
1 parent 27ad625 commit cc4b0e8
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 36 deletions.
71 changes: 50 additions & 21 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,34 @@ func AdaptTransaction(transaction *starknet.Transaction) (core.Transaction, erro

func AdaptDeclareTransaction(t *starknet.Transaction) *core.DeclareTransaction {
return &core.DeclareTransaction{
TransactionHash: t.Hash,
SenderAddress: t.SenderAddress,
MaxFee: t.MaxFee,
TransactionSignature: *t.Signature,
Nonce: t.Nonce,
Version: (*core.TransactionVersion)(t.Version),
ClassHash: t.ClassHash,
CompiledClassHash: t.CompiledClassHash,
TransactionHash: t.Hash,
SenderAddress: t.SenderAddress,
MaxFee: t.MaxFee,
TransactionSignature: *t.Signature,
Nonce: t.Nonce,
Version: (*core.TransactionVersion)(t.Version),
ClassHash: t.ClassHash,
CompiledClassHash: t.CompiledClassHash,
ResourceBounds: adaptResourceBounds(t.ResourceBounds),
Tip: t.Tip,
PaymasterData: t.PaymasterData,
AccountDeploymentData: t.AccountDeploymentData,
NonceDAMode: core.DataAvailabilityMode(t.NonceDAMode),
FeeDAMode: core.DataAvailabilityMode(t.FeeDAMode),
}
}

func adaptResourceBounds(rb map[starknet.Resource]*starknet.ResourceBounds) map[core.Resource]*core.ResourceBounds {
coreBounds := make(map[core.Resource]*core.ResourceBounds, len(rb))
for resource, bounds := range rb {
coreBounds[core.Resource(resource)] = &core.ResourceBounds{
MaxAmount: bounds.MaxAmount,
MaxPricePerUnit: bounds.MaxPricePerUnit,
}
}
return coreBounds
}

func AdaptDeployTransaction(t *starknet.Transaction) *core.DeployTransaction {
if t.ContractAddress == nil {
t.ContractAddress = core.ContractAddress(&felt.Zero, t.ClassHash, t.ContractAddressSalt, *t.ConstructorCallData)
Expand All @@ -183,15 +200,21 @@ func AdaptDeployTransaction(t *starknet.Transaction) *core.DeployTransaction {

func AdaptInvokeTransaction(t *starknet.Transaction) *core.InvokeTransaction {
return &core.InvokeTransaction{
TransactionHash: t.Hash,
ContractAddress: t.ContractAddress,
EntryPointSelector: t.EntryPointSelector,
Nonce: t.Nonce,
CallData: *t.CallData,
TransactionSignature: *t.Signature,
MaxFee: t.MaxFee,
Version: (*core.TransactionVersion)(t.Version),
SenderAddress: t.SenderAddress,
TransactionHash: t.Hash,
ContractAddress: t.ContractAddress,
EntryPointSelector: t.EntryPointSelector,
Nonce: t.Nonce,
CallData: *t.CallData,
TransactionSignature: *t.Signature,
MaxFee: t.MaxFee,
Version: (*core.TransactionVersion)(t.Version),
SenderAddress: t.SenderAddress,
ResourceBounds: adaptResourceBounds(t.ResourceBounds),
Tip: t.Tip,
PaymasterData: t.PaymasterData,
AccountDeploymentData: t.AccountDeploymentData,
NonceDAMode: core.DataAvailabilityMode(t.NonceDAMode),
FeeDAMode: core.DataAvailabilityMode(t.FeeDAMode),
}
}

Expand All @@ -208,10 +231,16 @@ func AdaptL1HandlerTransaction(t *starknet.Transaction) *core.L1HandlerTransacti

func AdaptDeployAccountTransaction(t *starknet.Transaction) *core.DeployAccountTransaction {
return &core.DeployAccountTransaction{
DeployTransaction: *AdaptDeployTransaction(t),
MaxFee: t.MaxFee,
TransactionSignature: *t.Signature,
Nonce: t.Nonce,
DeployTransaction: *AdaptDeployTransaction(t),
MaxFee: t.MaxFee,
TransactionSignature: *t.Signature,
Nonce: t.Nonce,
ResourceBounds: adaptResourceBounds(t.ResourceBounds),
Tip: t.Tip,
PaymasterData: t.PaymasterData,
AccountDeploymentData: t.AccountDeploymentData,
NonceDAMode: core.DataAvailabilityMode(t.NonceDAMode),
FeeDAMode: core.DataAvailabilityMode(t.FeeDAMode),
}
}

Expand Down
1 change: 0 additions & 1 deletion rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ func adaptBroadcastedTransaction(broadcastedTxn *BroadcastedTransaction,
network utils.Network,
) (core.Transaction, core.Class, *felt.Felt, error) {
var feederTxn starknet.Transaction
// TODO does this still work in v3 world?
if err := copier.Copy(&feederTxn, broadcastedTxn.Transaction); err != nil {
return nil, nil, nil, err
}
Expand Down
77 changes: 63 additions & 14 deletions starknet/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,71 @@ func (t *TransactionType) UnmarshalJSON(data []byte) error {
return nil
}

type Resource uint32

const (
ResourceL1Gas Resource = iota + 1
ResourceL2Gas
)

func (r *Resource) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"L1_GAS"`:
*r = ResourceL1Gas
case `"L2_GAS"`:
*r = ResourceL2Gas
default:
return fmt.Errorf("unknown resource: %s", string(data))
}
return nil
}

type DataAvailabilityMode uint32

const (
DAModeL1 DataAvailabilityMode = iota + 1
DAModeL2
)

func (da *DataAvailabilityMode) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"L1"`:
*da = DAModeL1
case `"L2"`:
*da = DAModeL2
default:
return fmt.Errorf("unknown DataAvailabilityMode: %s", string(data))
}
return nil
}

type ResourceBounds struct {
MaxAmount uint64 `json:"max_amount"`
MaxPricePerUnit *felt.Felt `json:"max_price_per_unit"`
}

// Transaction object returned by the feeder in JSON format for multiple endpoints
type Transaction struct {
Hash *felt.Felt `json:"transaction_hash,omitempty" copier:"must,nopanic"`
Version *felt.Felt `json:"version,omitempty"`
ContractAddress *felt.Felt `json:"contract_address,omitempty"`
ContractAddressSalt *felt.Felt `json:"contract_address_salt,omitempty"`
ClassHash *felt.Felt `json:"class_hash,omitempty"`
ConstructorCallData *[]*felt.Felt `json:"constructor_calldata,omitempty"`
Type TransactionType `json:"type,omitempty"`
SenderAddress *felt.Felt `json:"sender_address,omitempty"`
MaxFee *felt.Felt `json:"max_fee,omitempty"`
Signature *[]*felt.Felt `json:"signature,omitempty"`
CallData *[]*felt.Felt `json:"calldata,omitempty"`
EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"`
Nonce *felt.Felt `json:"nonce,omitempty"`
CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"`
Hash *felt.Felt `json:"transaction_hash,omitempty" copier:"must,nopanic"`
Version *felt.Felt `json:"version,omitempty"`
ContractAddress *felt.Felt `json:"contract_address,omitempty"`
ContractAddressSalt *felt.Felt `json:"contract_address_salt,omitempty"`
ClassHash *felt.Felt `json:"class_hash,omitempty"`
ConstructorCallData *[]*felt.Felt `json:"constructor_calldata,omitempty"`
Type TransactionType `json:"type,omitempty"`
SenderAddress *felt.Felt `json:"sender_address,omitempty"`
MaxFee *felt.Felt `json:"max_fee,omitempty"`
Signature *[]*felt.Felt `json:"signature,omitempty"`
CallData *[]*felt.Felt `json:"calldata,omitempty"`
EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"`
Nonce *felt.Felt `json:"nonce,omitempty"`
CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"`
ResourceBounds map[Resource]*ResourceBounds `json:"resource_bounds,omitempty"`
Tip uint64 `json:"tip,omitempty"`
NonceDAMode DataAvailabilityMode `json:"nonce_data_availability_mode,omitempty"`
FeeDAMode DataAvailabilityMode `json:"fee_data_availability_mode,omitempty"`
AccountDeploymentData []*felt.Felt `json:"account_deployment_data,omitempty"`
PaymasterData []*felt.Felt `json:"paymaster_data,omitempty"`
}

type TransactionStatus struct {
Expand Down

0 comments on commit cc4b0e8

Please sign in to comment.