Skip to content

Commit

Permalink
Send Ethereum style transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
palango committed Apr 9, 2024
1 parent bec59c2 commit 68073e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
21 changes: 6 additions & 15 deletions airgap/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,11 @@ type TxMetadata struct {

func (tm *TxMetadata) AsCallMessage() ethereum.CallMsg {
return ethereum.CallMsg{
From: tm.From,
GatewayFee: tm.GatewayFee,
GatewayFeeRecipient: tm.GatewayFeeRecipient,
GasPrice: tm.GasPrice,
To: &tm.To,
Data: tm.Data,
Value: tm.Value,
FeeCurrency: tm.FeeCurrency,
From: tm.From,
GasPrice: tm.GasPrice,
To: &tm.To,
Data: tm.Data,
Value: tm.Value,
}
}

Expand All @@ -151,15 +148,12 @@ func (tx *Transaction) Signed() bool {
}

func (tx *Transaction) AsGethTransaction() (*types.Transaction, error) {
gethTx := types.NewCeloTransaction(
gethTx := types.NewTransaction(
tx.Nonce,
tx.To,
tx.Value,
tx.Gas,
tx.GasPrice,
tx.FeeCurrency,
tx.GatewayFeeRecipient,
tx.GatewayFee,
tx.Data,
)
if tx.Signed() {
Expand Down Expand Up @@ -214,9 +208,6 @@ func (tx *Transaction) Deserialize(data []byte, chainId *big.Int) error {
tx.TxMetadata = &TxMetadata{}
tx.Nonce = gethTx.Nonce()
tx.GasPrice = gethTx.GasPrice()
tx.GatewayFee = gethTx.GatewayFee()
tx.GatewayFeeRecipient = gethTx.GatewayFeeRecipient()
tx.FeeCurrency = gethTx.FeeCurrency()
tx.To = *gethTx.To()
tx.Data = gethTx.Data()
tx.Value = gethTx.Value()
Expand Down
27 changes: 11 additions & 16 deletions airgap/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ func TestTransaction(t *testing.T) {
_, fromAddr, err := client.Derive(privKey)
Ω(err).ShouldNot(HaveOccurred())

addr2 := common.HexToAddress("0x2222")
addr3 := common.HexToAddress("0x3333")
newTx := func() *Transaction {
return &Transaction{
TxMetadata: &TxMetadata{
From: *fromAddr,
Nonce: 3,
GasPrice: big.NewInt(111),
GatewayFeeRecipient: &addr2,
GatewayFee: big.NewInt(222),
FeeCurrency: &addr3,
To: common.HexToAddress("0x4444"),
Data: []byte{1, 2, 3, 4},
Value: big.NewInt(4444),
Gas: 4,
ChainId: big.NewInt(42220),
From: *fromAddr,
Nonce: 3,
GasPrice: big.NewInt(111),
To: common.HexToAddress("0x4444"),
Data: []byte{1, 2, 3, 4},
Value: big.NewInt(4444),
Gas: 4,
ChainId: big.NewInt(42220),
},
}
}
Expand Down Expand Up @@ -84,11 +79,11 @@ func TestTransaction(t *testing.T) {
signedTxRaw, err := signedTx.Serialize()
Ω(err).ShouldNot(HaveOccurred())

var desrializedTx Transaction
err = desrializedTx.Deserialize(signedTxRaw, tx.ChainId)
var deserializedTx Transaction
err = deserializedTx.Deserialize(signedTxRaw, tx.ChainId)
Ω(err).ShouldNot(HaveOccurred())

Ω(desrializedTx).Should(Equal(*signedTx))
Ω(deserializedTx).Should(Equal(*signedTx))
})

}

0 comments on commit 68073e6

Please sign in to comment.