Skip to content

Commit

Permalink
feat: add the dynamic fee tx and support for typed txs
Browse files Browse the repository at this point in the history
  • Loading branch information
paologalligit committed Nov 29, 2024
1 parent 175050c commit 471f30b
Show file tree
Hide file tree
Showing 32 changed files with 835 additions and 253 deletions.
6 changes: 3 additions & 3 deletions api/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ func initAccountServer(t *testing.T) {
ts = httptest.NewServer(router)
}

func buildTxWithClauses(chaiTag byte, clauses ...*tx.Clause) *tx.Transaction {
func buildTxWithClauses(chainTag byte, clauses ...*tx.Clause) *tx.Transaction {
builder := new(tx.Builder).
ChainTag(chaiTag).
ChainTag(chainTag).
Expiration(10).
Gas(1000000)
for _, c := range clauses {
builder.Clause(c)
}

trx := builder.Build()
trx := builder.BuildLegacy()

return tx.MustSign(trx, genesis.DevAccounts()[0].PrivateKey)
}
Expand Down
2 changes: 1 addition & 1 deletion api/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func initBlockServer(t *testing.T) {
Nonce(1).
Clause(cla).
BlockRef(tx.NewBlockRef(0)).
Build(),
BuildLegacy(),
genesis.DevAccounts()[0].PrivateKey,
)

Expand Down
74 changes: 42 additions & 32 deletions api/blocks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package blocks

import (
"math/big"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/vechain/thor/v2/chain"
Expand Down Expand Up @@ -63,18 +65,20 @@ type JSONOutput struct {
}

type JSONEmbeddedTx struct {
ID thor.Bytes32 `json:"id"`
ChainTag byte `json:"chainTag"`
BlockRef string `json:"blockRef"`
Expiration uint32 `json:"expiration"`
Clauses []*JSONClause `json:"clauses"`
GasPriceCoef uint8 `json:"gasPriceCoef"`
Gas uint64 `json:"gas"`
Origin thor.Address `json:"origin"`
Delegator *thor.Address `json:"delegator"`
Nonce math.HexOrDecimal64 `json:"nonce"`
DependsOn *thor.Bytes32 `json:"dependsOn"`
Size uint32 `json:"size"`
ID thor.Bytes32 `json:"id"`
ChainTag byte `json:"chainTag"`
BlockRef string `json:"blockRef"`
Expiration uint32 `json:"expiration"`
Clauses []*JSONClause `json:"clauses"`
GasPriceCoef uint8 `json:"gasPriceCoef"`
MaxFeePerGas *big.Int `json:"maxFeePerGas,omitempty"`
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas,omitempty"`
Gas uint64 `json:"gas"`
Origin thor.Address `json:"origin"`
Delegator *thor.Address `json:"delegator"`
Nonce math.HexOrDecimal64 `json:"nonce"`
DependsOn *thor.Bytes32 `json:"dependsOn"`
Size uint32 `json:"size"`

// receipt part
GasUsed uint64 `json:"gasUsed"`
Expand Down Expand Up @@ -144,13 +148,13 @@ func buildJSONOutput(txID thor.Bytes32, index uint32, c *tx.Clause, o *tx.Output

func buildJSONEmbeddedTxs(txs tx.Transactions, receipts tx.Receipts) []*JSONEmbeddedTx {
jTxs := make([]*JSONEmbeddedTx, 0, len(txs))
for itx, tx := range txs {
for itx, trx := range txs {
receipt := receipts[itx]

clauses := tx.Clauses()
blockRef := tx.BlockRef()
origin, _ := tx.Origin()
delegator, _ := tx.Delegator()
clauses := trx.Clauses()
blockRef := trx.BlockRef()
origin, _ := trx.Origin()
delegator, _ := trx.Delegator()

jcs := make([]*JSONClause, 0, len(clauses))
jos := make([]*JSONOutput, 0, len(receipt.Outputs))
Expand All @@ -162,31 +166,37 @@ func buildJSONEmbeddedTxs(txs tx.Transactions, receipts tx.Receipts) []*JSONEmbe
hexutil.Encode(c.Data()),
})
if !receipt.Reverted {
jos = append(jos, buildJSONOutput(tx.ID(), uint32(i), c, receipt.Outputs[i]))
jos = append(jos, buildJSONOutput(trx.ID(), uint32(i), c, receipt.Outputs[i]))
}
}

jTxs = append(jTxs, &JSONEmbeddedTx{
ID: tx.ID(),
ChainTag: tx.ChainTag(),
BlockRef: hexutil.Encode(blockRef[:]),
Expiration: tx.Expiration(),
Clauses: jcs,
GasPriceCoef: tx.GasPriceCoef(),
Gas: tx.Gas(),
Origin: origin,
Delegator: delegator,
Nonce: math.HexOrDecimal64(tx.Nonce()),
DependsOn: tx.DependsOn(),
Size: uint32(tx.Size()),
embedTx := &JSONEmbeddedTx{
ID: trx.ID(),
ChainTag: trx.ChainTag(),
BlockRef: hexutil.Encode(blockRef[:]),
Expiration: trx.Expiration(),
Clauses: jcs,
Gas: trx.Gas(),
Origin: origin,
Delegator: delegator,
Nonce: math.HexOrDecimal64(trx.Nonce()),
DependsOn: trx.DependsOn(),
Size: uint32(trx.Size()),

GasUsed: receipt.GasUsed,
GasPayer: receipt.GasPayer,
Paid: (*math.HexOrDecimal256)(receipt.Paid),
Reward: (*math.HexOrDecimal256)(receipt.Reward),
Reverted: receipt.Reverted,
Outputs: jos,
})
}
if trx.Type() == tx.LegacyTxType {
embedTx.GasPriceCoef = trx.GasPriceCoef()
} else {
embedTx.MaxFeePerGas = trx.MaxFeePerGas()
embedTx.MaxPriorityFeePerGas = trx.MaxPriorityFeePerGas()
}
jTxs = append(jTxs, embedTx)
}
return jTxs
}
4 changes: 2 additions & 2 deletions api/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func initDebugServer(t *testing.T) {
ChainTag(repo.ChainTag()).
Expiration(10).
Gas(21000).
Build()
BuildLegacy()
noClausesTx = tx.MustSign(noClausesTx, genesis.DevAccounts()[0].PrivateKey)

cla := tx.NewClause(&addr).WithValue(big.NewInt(10000))
Expand All @@ -544,7 +544,7 @@ func initDebugServer(t *testing.T) {
Clause(cla).
Clause(cla2).
BlockRef(tx.NewBlockRef(0)).
Build()
BuildLegacy()
transaction = tx.MustSign(transaction, genesis.DevAccounts()[0].PrivateKey)

packer := packer.New(repo, stater, genesis.DevAccounts()[0].Address, &genesis.DevAccounts()[0].Address, thor.NoFork)
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/block_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func initChain(t *testing.T) (*chain.Repository, []*block.Block, *txpool.TxPool)
Nonce(1).
Clause(cla).
BlockRef(tx.NewBlockRef(0)).
Build()
BuildLegacy()
tr = tx.MustSign(tr, genesis.DevAccounts()[0].PrivateKey)

packer := packer.New(repo, stater, genesis.DevAccounts()[0].Address, &genesis.DevAccounts()[0].Address, thor.NoFork)
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/pending_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func createTx(repo *chain.Repository, addressNumber uint) *tx.Transaction {
Nonce(1).
Clause(cla).
BlockRef(tx.NewBlockRef(0)).
Build(),
BuildLegacy(),
genesis.DevAccounts()[addressNumber].PrivateKey,
)
}
6 changes: 3 additions & 3 deletions api/subscriptions/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestConvertTransfer(t *testing.T) {
Gas(21000).
Nonce(1).
BlockRef(tx.NewBlockRef(0)).
Build()
BuildLegacy()
transaction = tx.MustSign(transaction, genesis.DevAccounts()[0].PrivateKey)

// New block
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestConvertEventWithBadSignature(t *testing.T) {
Gas(21000).
Nonce(1).
BlockRef(tx.NewBlockRef(0)).
Build().
BuildLegacy().
WithSignature(badSig[:])

// New block
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestConvertEvent(t *testing.T) {
Gas(21000).
Nonce(1).
BlockRef(tx.NewBlockRef(0)).
Build(),
BuildLegacy(),
genesis.DevAccounts()[0].PrivateKey,
)

Expand Down
Loading

0 comments on commit 471f30b

Please sign in to comment.