Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 8 additions & 11 deletions airgap/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,14 @@ type FilterQueryParams struct {
}

type TxMetadata struct {
From common.Address
Nonce uint64
GasPrice *big.Int
GatewayFeeRecipient *common.Address
GatewayFee *big.Int
FeeCurrency *common.Address
To common.Address
Data []byte
Value *big.Int
Gas uint64
ChainId *big.Int
From common.Address
Nonce uint64
GasPrice *big.Int
To common.Address
Data []byte
Value *big.Int
Gas uint64
ChainId *big.Int
}

func (tm *TxMetadata) AsCallMessage() ethereum.CallMsg {
Expand Down
12 changes: 5 additions & 7 deletions airgap/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ func (b *airGapServerImpl) ObtainMetadata(ctx context.Context, options *airgap.T
}

txMetadata := airgap.TxMetadata{
From: options.From,
Nonce: nonce,
GasPrice: gasPrice,
GatewayFee: nil,
GatewayFeeRecipient: nil,
Value: options.Value,
ChainId: b.chainId,
From: options.From,
Nonce: nonce,
GasPrice: gasPrice,
Value: options.Value,
ChainId: b.chainId,
}

if options.To != nil {
Expand Down
51 changes: 18 additions & 33 deletions airgap/transaction_marshall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,20 @@ import (

func (tx Transaction) MarshalJSON() ([]byte, error) {
var data struct {
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
GatewayFeeRecipient *common.Address `json:"gatewayFeeRecipient,omitempty"`
GatewayFee *string `json:"gatewayFee,omitempty"`
FeeCurrency *common.Address `json:"feeCurrency,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
Signature string `json:"signature"`
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
Signature string `json:"signature"`
}

data.From = tx.From
data.Nonce = tx.Nonce
data.GasPrice = bigIntToString(tx.GasPrice)
data.GatewayFeeRecipient = tx.GatewayFeeRecipient
data.GatewayFee = bigIntToString(tx.GatewayFee)
data.FeeCurrency = tx.FeeCurrency
data.To = tx.To
data.Data = common.Bytes2Hex(tx.Data)
data.Value = bigIntToString(tx.Value)
Expand All @@ -55,18 +49,15 @@ func (tx Transaction) MarshalJSON() ([]byte, error) {
func (tx *Transaction) UnmarshalJSON(b []byte) error {
var err error
var data struct {
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
GatewayFeeRecipient *common.Address `json:"gatewayFeeRecipient,omitempty"`
GatewayFee *string `json:"gatewayFee,omitempty"`
FeeCurrency *common.Address `json:"feeCurrency,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
Signature string `json:"signature"`
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
Signature string `json:"signature"`
}

if err = json.Unmarshal(b, &data); err != nil {
Expand All @@ -81,12 +72,6 @@ func (tx *Transaction) UnmarshalJSON(b []byte) error {
if err != nil {
return err
}
tx.GatewayFeeRecipient = data.GatewayFeeRecipient
tx.GatewayFee, err = stringToBigInt(data.GatewayFee)
if err != nil {
return err
}
tx.FeeCurrency = data.FeeCurrency
tx.To = data.To
tx.Data = common.Hex2Bytes(data.Data)
tx.Value, err = stringToBigInt(data.Value)
Expand Down
22 changes: 8 additions & 14 deletions airgap/transaction_marshall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import (
func TestTransactionMarshalling(t *testing.T) {
RegisterTestingT(t)

address1 := common.HexToAddress("0x11111")
address2 := common.HexToAddress("0x22222")

samples := []struct {
name string
sample Transaction
Expand All @@ -36,17 +33,14 @@ func TestTransactionMarshalling(t *testing.T) {
name: "Complete",
sample: Transaction{
TxMetadata: &TxMetadata{
From: common.HexToAddress("0x55555"),
Nonce: 70,
GasPrice: big.NewInt(5000),
GatewayFeeRecipient: &address1,
GatewayFee: big.NewInt(5000),
FeeCurrency: &address2,
To: common.HexToAddress("0x33333"),
Data: []byte{1, 2, 3},
Value: big.NewInt(3000),
Gas: 98,
ChainId: big.NewInt(2000),
From: common.HexToAddress("0x55555"),
Nonce: 70,
GasPrice: big.NewInt(5000),
To: common.HexToAddress("0x33333"),
Data: []byte{1, 2, 3},
Value: big.NewInt(3000),
Gas: 98,
ChainId: big.NewInt(2000),
},
Signature: []byte{1, 2, 3},
},
Expand Down
47 changes: 16 additions & 31 deletions airgap/txmetadata_marshall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,19 @@ import (

func (tm TxMetadata) MarshalJSON() ([]byte, error) {
var data struct {
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
GatewayFeeRecipient *common.Address `json:"gatewayFeeRecipient,omitempty"`
GatewayFee *string `json:"gatewayFee,omitempty"`
FeeCurrency *common.Address `json:"feeCurrency,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
}

data.From = tm.From
data.Nonce = tm.Nonce
data.GasPrice = bigIntToString(tm.GasPrice)
data.GatewayFeeRecipient = tm.GatewayFeeRecipient
data.GatewayFee = bigIntToString(tm.GatewayFee)
data.FeeCurrency = tm.FeeCurrency
data.To = tm.To
data.Data = common.Bytes2Hex(tm.Data)
data.Value = bigIntToString(tm.Value)
Expand All @@ -53,17 +47,14 @@ func (tm TxMetadata) MarshalJSON() ([]byte, error) {
func (tm *TxMetadata) UnmarshalJSON(b []byte) error {
var err error
var data struct {
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
GatewayFeeRecipient *common.Address `json:"gatewayFeeRecipient,omitempty"`
GatewayFee *string `json:"gatewayFee,omitempty"`
FeeCurrency *common.Address `json:"feeCurrency,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
From common.Address `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *string `json:"gasPrice,omitempty"`
To common.Address `json:"to"`
Data string `json:"data"`
Value *string `json:"value,omitempty"`
Gas uint64 `json:"gas"`
ChainId string `json:"chainId"`
}

if err = json.Unmarshal(b, &data); err != nil {
Expand All @@ -76,12 +67,6 @@ func (tm *TxMetadata) UnmarshalJSON(b []byte) error {
if err != nil {
return err
}
tm.GatewayFeeRecipient = data.GatewayFeeRecipient
tm.GatewayFee, err = stringToBigInt(data.GatewayFee)
if err != nil {
return err
}
tm.FeeCurrency = data.FeeCurrency
tm.To = data.To
tm.Data = common.Hex2Bytes(data.Data)
tm.Value, err = stringToBigInt(data.Value)
Expand Down
22 changes: 8 additions & 14 deletions airgap/txmetadata_marshall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,21 @@ import (
func TestTxMetadataMarshalling(t *testing.T) {
RegisterTestingT(t)

address1 := common.HexToAddress("0x11111")
address2 := common.HexToAddress("0x22222")

samples := []struct {
name string
sample TxMetadata
}{
{
name: "Complete",
sample: TxMetadata{
From: common.HexToAddress("0x55555"),
Nonce: 70,
GasPrice: big.NewInt(5000),
GatewayFeeRecipient: &address1,
GatewayFee: big.NewInt(5000),
FeeCurrency: &address2,
To: common.HexToAddress("0x33333"),
Data: []byte{1, 2, 3},
Value: big.NewInt(3000),
Gas: 98,
ChainId: big.NewInt(2000),
From: common.HexToAddress("0x55555"),
Nonce: 70,
GasPrice: big.NewInt(5000),
To: common.HexToAddress("0x33333"),
Data: []byte{1, 2, 3},
Value: big.NewInt(3000),
Gas: 98,
ChainId: big.NewInt(2000),
},
},
{
Expand Down