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,17 +21,6 @@ var ( ...@@ -21,17 +21,6 @@ var (
ErrUnknownDeposit = errors.New("unknown deposit") ErrUnknownDeposit = errors.New("unknown deposit")
) )
// 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 holds metadata about a tx on either the L1 or L2 chain. // ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.
type ConfirmationInfo struct { type ConfirmationInfo struct {
TxnHash common.Hash TxnHash common.Hash
...@@ -39,15 +28,27 @@ type ConfirmationInfo struct { ...@@ -39,15 +28,27 @@ type ConfirmationInfo struct {
BlockTimestamp time.Time 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
Address common.Address
Amount *big.Int
ConfirmationInfo
}
type Disbursement struct {
Success bool
ConfirmationInfo
}
// 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,
......
...@@ -91,12 +91,14 @@ func TestUpsertDeposits(t *testing.T) { ...@@ -91,12 +91,14 @@ func TestUpsertDeposits(t *testing.T) {
defer d.Close() defer d.Close()
deposit1 := db.Deposit{ deposit1 := db.Deposit{
ID: 1, ID: 1,
TxnHash: common.HexToHash("0xff01"), Address: common.HexToAddress("0xaa01"),
BlockNumber: 1, Amount: big.NewInt(1),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa01"), TxnHash: common.HexToHash("0xff01"),
Amount: big.NewInt(1), BlockNumber: 1,
BlockTimestamp: testTimestamp,
},
} }
err := d.UpsertDeposits([]db.Deposit{deposit1}, 0) err := d.UpsertDeposits([]db.Deposit{deposit1}, 0)
...@@ -107,12 +109,14 @@ func TestUpsertDeposits(t *testing.T) { ...@@ -107,12 +109,14 @@ func TestUpsertDeposits(t *testing.T) {
require.Equal(t, deposits, []db.Deposit{deposit1}) require.Equal(t, deposits, []db.Deposit{deposit1})
deposit2 := db.Deposit{ deposit2 := db.Deposit{
ID: 1, ID: 1,
TxnHash: common.HexToHash("0xff02"), Address: common.HexToAddress("0xaa02"),
BlockNumber: 2, Amount: big.NewInt(2),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa02"), TxnHash: common.HexToHash("0xff02"),
Amount: big.NewInt(2), BlockNumber: 2,
BlockTimestamp: testTimestamp,
},
} }
err = d.UpsertDeposits([]db.Deposit{deposit2}, 0) err = d.UpsertDeposits([]db.Deposit{deposit2}, 0)
...@@ -160,12 +164,14 @@ func TestUpsertDepositsRecordsLastProcessedBlock(t *testing.T) { ...@@ -160,12 +164,14 @@ 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,
TxnHash: common.HexToHash("0xff03"), Address: common.HexToAddress("0xaa03"),
BlockNumber: 3, Amount: big.NewInt(3),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa03"), TxnHash: common.HexToHash("0xff03"),
Amount: big.NewInt(3), BlockNumber: 3,
BlockTimestamp: testTimestamp,
},
} }
err = d.UpsertDeposits([]db.Deposit{deposit}, 4) err = d.UpsertDeposits([]db.Deposit{deposit}, 4)
require.Nil(t, err) require.Nil(t, err)
...@@ -190,28 +196,34 @@ func TestConfirmedDeposits(t *testing.T) { ...@@ -190,28 +196,34 @@ func TestConfirmedDeposits(t *testing.T) {
require.Equal(t, int(0), len(deposits)) require.Equal(t, int(0), len(deposits))
deposit1 := db.Deposit{ deposit1 := db.Deposit{
ID: 1, ID: 1,
TxnHash: common.HexToHash("0xff01"), Address: common.HexToAddress("0xaa01"),
BlockNumber: 1, Amount: big.NewInt(1),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa01"), TxnHash: common.HexToHash("0xff01"),
Amount: big.NewInt(1), BlockNumber: 1,
BlockTimestamp: testTimestamp,
},
} }
deposit2 := db.Deposit{ deposit2 := db.Deposit{
ID: 2, ID: 2,
TxnHash: common.HexToHash("0xff21"), Address: common.HexToAddress("0xaa21"),
BlockNumber: 2, Amount: big.NewInt(2),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa21"), TxnHash: common.HexToHash("0xff21"),
Amount: big.NewInt(2), BlockNumber: 2,
BlockTimestamp: testTimestamp,
},
} }
deposit3 := db.Deposit{ deposit3 := db.Deposit{
ID: 3, ID: 3,
TxnHash: common.HexToHash("0xff22"), Address: common.HexToAddress("0xaa22"),
BlockNumber: 2, Amount: big.NewInt(2),
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: common.HexToAddress("0xaa22"), TxnHash: common.HexToHash("0xff22"),
Amount: big.NewInt(2), BlockNumber: 2,
BlockTimestamp: testTimestamp,
},
} }
err = d.UpsertDeposits([]db.Deposit{ err = d.UpsertDeposits([]db.Deposit{
...@@ -269,12 +281,14 @@ func TestUpsertDisbursement(t *testing.T) { ...@@ -269,12 +281,14 @@ func TestUpsertDisbursement(t *testing.T) {
// Now, insert a real deposit that we will disburse. // Now, insert a real deposit that we will disburse.
err = d.UpsertDeposits([]db.Deposit{ err = d.UpsertDeposits([]db.Deposit{
{ {
ID: 1, ID: 1,
TxnHash: depTxnHash, Address: address,
BlockNumber: depBlockNumber, Amount: amount,
BlockTimestamp: testTimestamp, ConfirmationInfo: db.ConfirmationInfo{
Address: address, TxnHash: depTxnHash,
Amount: amount, BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp,
},
}, },
}, 0) }, 0)
require.Nil(t, err) require.Nil(t, err)
...@@ -289,19 +303,23 @@ func TestUpsertDisbursement(t *testing.T) { ...@@ -289,19 +303,23 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports := []db.CompletedTeleport{ expTeleports := []db.CompletedTeleport{
{ {
ID: 1, Deposit: db.Deposit{
Address: address, ID: 1,
Amount: amount, Address: address,
Success: false, Amount: amount,
Deposit: db.ConfirmationInfo{ ConfirmationInfo: db.ConfirmationInfo{
TxnHash: depTxnHash, TxnHash: depTxnHash,
BlockNumber: depBlockNumber, BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp, BlockTimestamp: testTimestamp,
},
}, },
Disbursement: db.ConfirmationInfo{ Disbursement: db.Disbursement{
TxnHash: tempDisTxnHash, Success: false,
BlockNumber: tempDisBlockNumber, ConfirmationInfo: db.ConfirmationInfo{
BlockTimestamp: testTimestamp, TxnHash: tempDisTxnHash,
BlockNumber: tempDisBlockNumber,
BlockTimestamp: testTimestamp,
},
}, },
}, },
} }
...@@ -318,19 +336,23 @@ func TestUpsertDisbursement(t *testing.T) { ...@@ -318,19 +336,23 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports = []db.CompletedTeleport{ expTeleports = []db.CompletedTeleport{
{ {
ID: 1, Deposit: db.Deposit{
Address: address, ID: 1,
Amount: amount, Address: address,
Success: true, Amount: amount,
Deposit: db.ConfirmationInfo{ ConfirmationInfo: db.ConfirmationInfo{
TxnHash: depTxnHash, TxnHash: depTxnHash,
BlockNumber: depBlockNumber, BlockNumber: depBlockNumber,
BlockTimestamp: testTimestamp, BlockTimestamp: testTimestamp,
},
}, },
Disbursement: db.ConfirmationInfo{ Disbursement: db.Disbursement{
TxnHash: disTxnHash, Success: true,
BlockNumber: disBlockNumber, ConfirmationInfo: db.ConfirmationInfo{
BlockTimestamp: testTimestamp, TxnHash: disTxnHash,
BlockNumber: disBlockNumber,
BlockTimestamp: testTimestamp,
},
}, },
}, },
} }
......
...@@ -509,12 +509,14 @@ func (d *Driver) ingestDeposits( ...@@ -509,12 +509,14 @@ func (d *Driver) ingestDeposits(
} }
deposits = append(deposits, db.Deposit{ deposits = append(deposits, db.Deposit{
ID: event.DepositId.Uint64(), ID: event.DepositId.Uint64(),
TxnHash: event.Raw.TxHash, Address: event.Emitter,
BlockNumber: event.Raw.BlockNumber, Amount: event.Amount,
BlockTimestamp: time.Unix(int64(header.Time), 0), ConfirmationInfo: db.ConfirmationInfo{
Address: event.Emitter, TxnHash: event.Raw.TxHash,
Amount: event.Amount, BlockNumber: event.Raw.BlockNumber,
BlockTimestamp: time.Unix(int64(header.Time), 0),
},
}) })
} }
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