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