Commit bf1cc8f4 authored by Conner Fromknecht's avatar Conner Fromknecht

feat: restructure Deposit and CompletedTelport w/ struct embeddings

parent cdb61a31
---
'@eth-optimism/teleportr': patch
---
Restructure Deposit and CompletedTeleport to use struct embeddings
......@@ -21,33 +21,34 @@ var (
ErrUnknownDeposit = errors.New("unknown deposit")
)
// ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.
type ConfirmationInfo struct {
TxnHash common.Hash
BlockNumber uint64
BlockTimestamp time.Time
}
// Deposit represents an event emitted from the TeleportrDeposit contract on L1,
// along with additional info about the tx that generated the event.
type Deposit struct {
ID uint64
TxnHash common.Hash
BlockNumber uint64
BlockTimestamp time.Time
Address common.Address
Amount *big.Int
ConfirmationInfo
}
// ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.
type ConfirmationInfo struct {
TxnHash common.Hash
BlockNumber uint64
BlockTimestamp time.Time
type Disbursement struct {
Success bool
ConfirmationInfo
}
// CompletedTeleport represents an L1 deposit that has been disbursed on L2. The
// struct also hold info about the L1 and L2 txns involved.
type CompletedTeleport struct {
ID uint64
Address common.Address
Amount *big.Int
Success bool
Deposit ConfirmationInfo
Disbursement ConfirmationInfo
Deposit
Disbursement Disbursement
}
const createDepositsTable = `
......@@ -401,7 +402,7 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
&teleport.ID,
&addressStr,
&amountStr,
&teleport.Success,
&teleport.Disbursement.Success,
&depTxnHashStr,
&teleport.Deposit.BlockNumber,
&teleport.Deposit.BlockTimestamp,
......
......@@ -92,11 +92,13 @@ func TestUpsertDeposits(t *testing.T) {
deposit1 := db.Deposit{
ID: 1,
Address: common.HexToAddress("0xaa01"),
Amount: big.NewInt(1),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff01"),
BlockNumber: 1,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa01"),
Amount: big.NewInt(1),
},
}
err := d.UpsertDeposits([]db.Deposit{deposit1}, 0)
......@@ -108,11 +110,13 @@ func TestUpsertDeposits(t *testing.T) {
deposit2 := db.Deposit{
ID: 1,
Address: common.HexToAddress("0xaa02"),
Amount: big.NewInt(2),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff02"),
BlockNumber: 2,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa02"),
Amount: big.NewInt(2),
},
}
err = d.UpsertDeposits([]db.Deposit{deposit2}, 0)
......@@ -161,11 +165,13 @@ func TestUpsertDepositsRecordsLastProcessedBlock(t *testing.T) {
// Insert real deposit in block 3 with last processed at 4.
deposit := db.Deposit{
ID: 0,
Address: common.HexToAddress("0xaa03"),
Amount: big.NewInt(3),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff03"),
BlockNumber: 3,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa03"),
Amount: big.NewInt(3),
},
}
err = d.UpsertDeposits([]db.Deposit{deposit}, 4)
require.Nil(t, err)
......@@ -191,27 +197,33 @@ func TestConfirmedDeposits(t *testing.T) {
deposit1 := db.Deposit{
ID: 1,
Address: common.HexToAddress("0xaa01"),
Amount: big.NewInt(1),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff01"),
BlockNumber: 1,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa01"),
Amount: big.NewInt(1),
},
}
deposit2 := db.Deposit{
ID: 2,
Address: common.HexToAddress("0xaa21"),
Amount: big.NewInt(2),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff21"),
BlockNumber: 2,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa21"),
Amount: big.NewInt(2),
},
}
deposit3 := db.Deposit{
ID: 3,
Address: common.HexToAddress("0xaa22"),
Amount: big.NewInt(2),
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: common.HexToHash("0xff22"),
BlockNumber: 2,
BlockTimestamp: testTimestamp,
Address: common.HexToAddress("0xaa22"),
Amount: big.NewInt(2),
},
}
err = d.UpsertDeposits([]db.Deposit{
......@@ -270,11 +282,13 @@ func TestUpsertDisbursement(t *testing.T) {
err = d.UpsertDeposits([]db.Deposit{
{
ID: 1,
Address: address,
Amount: amount,
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: depTxnHash,
BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp,
Address: address,
Amount: amount,
},
},
}, 0)
require.Nil(t, err)
......@@ -289,21 +303,25 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports := []db.CompletedTeleport{
{
Deposit: db.Deposit{
ID: 1,
Address: address,
Amount: amount,
Success: false,
Deposit: db.ConfirmationInfo{
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: depTxnHash,
BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp,
},
Disbursement: db.ConfirmationInfo{
},
Disbursement: db.Disbursement{
Success: false,
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: tempDisTxnHash,
BlockNumber: tempDisBlockNumber,
BlockTimestamp: testTimestamp,
},
},
},
}
// Assert that the deposit shows up in the CompletedTeleports method with
......@@ -318,21 +336,25 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports = []db.CompletedTeleport{
{
Deposit: db.Deposit{
ID: 1,
Address: address,
Amount: amount,
Success: true,
Deposit: db.ConfirmationInfo{
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: depTxnHash,
BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp,
},
Disbursement: db.ConfirmationInfo{
},
Disbursement: db.Disbursement{
Success: true,
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: disTxnHash,
BlockNumber: disBlockNumber,
BlockTimestamp: testTimestamp,
},
},
},
}
// Assert that the deposit now shows up in the CompletedTeleports method
......
......@@ -510,11 +510,13 @@ func (d *Driver) ingestDeposits(
deposits = append(deposits, db.Deposit{
ID: event.DepositId.Uint64(),
Address: event.Emitter,
Amount: event.Amount,
ConfirmationInfo: db.ConfirmationInfo{
TxnHash: event.Raw.TxHash,
BlockNumber: event.Raw.BlockNumber,
BlockTimestamp: time.Unix(int64(header.Time), 0),
Address: event.Emitter,
Amount: event.Amount,
},
})
}
err = events.Error()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment