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