Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ Packages:
- `ethartifacts`: simple pkg to parse Truffle artifact file
- `ethcoder`: encoding/decoding libraries for smart contracts and transactions
- `ethdeploy`: simple method to deploy contract bytecode to a network
- `ethfinalizer`: a wallet adapter for guaranteeing transaction inclusion
- `ethgas`: fetch the latest gas price of a network or track over a period of time
- `ethmonitor`: easily monitor block production, transactions and logs of a chain; with re-org support
- `ethrpc`: http client for Ethereum json-rpc
- `ethwallet`: wallet for Ethereum with support for wallet mnemonics (BIP-39)
- `finalizer`: a wallet adapter for guaranteeing transaction inclusion on a specific chain

## License

Expand Down
24 changes: 12 additions & 12 deletions finalizer/README.md → ethfinalizer/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Finalizer
# ethfinalizer

A wallet adapter for guaranteeing transaction inclusion on a specific chain.

Expand All @@ -11,7 +11,7 @@ This fixes "nonce too low" issues that can happen if reorgs occur or if you trus
For demonstration:

```go
mempool := finalizer.NewMemoryMempool[struct{}]()
mempool := ethfinalizer.NewMemoryMempool[struct{}]()
```

Here `struct{}` can be any type for transaction metadata, data that gets persisted with the transaction, but not sent on chain.
Expand All @@ -23,7 +23,7 @@ For production, implement the `Mempool` interface and persist to a database inst
For EIP-1559 chains:

```go
chain, err := finalizer.NewEthkitChain(finalizer.EthkitChainOptions{
chain, err := ethfinalizer.NewEthkitChain(ethfinalizer.EthkitChainOptions{
ChainID: big.NewInt(1),
IsEIP1559: true,
Provider: provider,
Expand All @@ -36,21 +36,21 @@ chain, err := finalizer.NewEthkitChain(finalizer.EthkitChainOptions{
For non-EIP-1559 chains:

```go
chain, err := finalizer.NewEthkitChain(finalizer.EthkitChainOptions{
chain, err := ethfinalizer.NewEthkitChain(ethfinalizer.EthkitChainOptions{
ChainID: big.NewInt(56),
IsEIP1559: false,
Provider: provider,
Monitor: monitor, // must be running
GasGauge: gasGauge, // required for non-EIP-1559 chains
GasGaugeSpeed: finalizer.GasGaugeSpeedDefault // default = fast
PriorityFee: nil, // not used for non-EIP-1559 chains
Monitor: monitor, // must be running
GasGauge: gasGauge, // required for non-EIP-1559 chains
GasGaugeSpeed: ethfinalizer.GasGaugeSpeedDefault // default = fast
PriorityFee: nil, // not used for non-EIP-1559 chains
})
```

### Create a finalizer for a specific wallet on a specific chain

```go
f, err := finalizer.NewFinalizer(finalizer.FinalizerOptions[struct{}]{
finalizer, err := ethfinalizer.NewFinalizer(ethfinalizer.FinalizerOptions[struct{}]{
Wallet: wallet,
Chain: chain,
Mempool: mempool,
Expand All @@ -66,13 +66,13 @@ f, err := finalizer.NewFinalizer(finalizer.FinalizerOptions[struct{}]{
The finalizer has a blocking run loop that must be called for it to work:

```go
err := f.Run(ctx)
err := finalizer.Run(ctx)
```

### Subscribe to mining and reorg events

```go
for event := range f.Subscribe(ctx) {
for event := range finalizer.Subscribe(ctx) {
if event.Added != nil {
if event.Removed == nil {
fmt.Println(
Expand Down Expand Up @@ -103,7 +103,7 @@ for event := range f.Subscribe(ctx) {
### Send a transaction

```go
signed, err := f.Send(ctx, unsigned, struct{}{})
signed, err := finalizer.Send(ctx, unsigned, struct{}{})
```

The `struct{}{}` argument here is the transaction's metadata.
Expand Down
2 changes: 1 addition & 1 deletion finalizer/chain.go → ethfinalizer/chain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package finalizer
package ethfinalizer

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions finalizer/finalizer.go → ethfinalizer/ethfinalizer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package finalizer implements a wallet adapter for guaranteeing transaction inclusion on a specific chain.
// Package ethfinalizer implements a wallet adapter for guaranteeing transaction inclusion on a specific chain.
//
// This fixes "nonce too low" issues that can happen if reorgs occur or if you trust your node's reported nonces.
package finalizer
package ethfinalizer

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package finalizer_test
package ethfinalizer_test

import (
"context"
Expand All @@ -11,8 +11,8 @@ import (
"testing"
"time"

"github.com/0xsequence/ethkit/ethfinalizer"
"github.com/0xsequence/ethkit/ethwallet"
"github.com/0xsequence/ethkit/finalizer"
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/ethkit/go-ethereum/core/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -60,9 +60,9 @@ func test(t *testing.T, isEIP1559 bool) {
})
assert.NoError(t, err)

mempool := finalizer.NewMemoryMempool[struct{}]()
mempool := ethfinalizer.NewMemoryMempool[struct{}]()

finalizer, err := finalizer.NewFinalizer(finalizer.FinalizerOptions[struct{}]{
finalizer, err := ethfinalizer.NewFinalizer(ethfinalizer.FinalizerOptions[struct{}]{
Wallet: wallet,
Chain: chain,
Mempool: mempool,
Expand Down Expand Up @@ -228,7 +228,7 @@ type TestChain struct {
highestNonce *uint64
mu sync.RWMutex

subscriptions map[chan finalizer.Diff]struct{}
subscriptions map[chan ethfinalizer.Diff]struct{}
subscriptionsMu sync.RWMutex
}

Expand All @@ -246,7 +246,7 @@ func NewTestChain(options TestChainOptions) (*TestChain, error) {

mempool: map[uint64][]*types.Transaction{},

subscriptions: map[chan finalizer.Diff]struct{}{},
subscriptions: map[chan ethfinalizer.Diff]struct{}{},
}, nil
}

Expand Down Expand Up @@ -284,7 +284,7 @@ func (c *TestChain) Publish() {
c.subscriptionsMu.RLock()
defer c.subscriptionsMu.RUnlock()

diff := finalizer.Diff{
diff := ethfinalizer.Diff{
Removed: map[common.Hash]struct{}{},
Added: map[common.Hash]struct{}{},
}
Expand Down Expand Up @@ -367,11 +367,11 @@ func (c *TestChain) PriorityFee(ctx context.Context) (*big.Int, error) {
return new(big.Int).SetUint64(uniform(c.MinPriorityFee, c.MaxPriorityFee)), nil
}

func (c *TestChain) Subscribe(ctx context.Context) (<-chan finalizer.Diff, error) {
func (c *TestChain) Subscribe(ctx context.Context) (<-chan ethfinalizer.Diff, error) {
c.subscriptionsMu.Lock()
defer c.subscriptionsMu.Unlock()

subscription := make(chan finalizer.Diff)
subscription := make(chan ethfinalizer.Diff)
c.subscriptions[subscription] = struct{}{}

go func() {
Expand Down
2 changes: 1 addition & 1 deletion finalizer/mempool.go → ethfinalizer/mempool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package finalizer
package ethfinalizer

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion finalizer/utils.go → ethfinalizer/utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package finalizer
package ethfinalizer

import (
"fmt"
Expand Down
Loading