Commit 59ff146c authored by Conner Fromknecht's avatar Conner Fromknecht

feat: use uint64 for deposit ids and block numbers

Less casting.
parent 6af67df5
...@@ -24,9 +24,9 @@ var ( ...@@ -24,9 +24,9 @@ var (
// 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 int64 ID uint64
TxnHash common.Hash TxnHash common.Hash
BlockNumber int64 BlockNumber uint64
BlockTimestamp time.Time BlockTimestamp time.Time
Address common.Address Address common.Address
Amount *big.Int Amount *big.Int
...@@ -35,14 +35,14 @@ type Deposit struct { ...@@ -35,14 +35,14 @@ type Deposit struct {
// 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
BlockNumber int64 BlockNumber uint64
BlockTimestamp time.Time 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 int64 ID uint64
Address common.Address Address common.Address
Amount *big.Int Amount *big.Int
Deposit ConfirmationInfo Deposit ConfirmationInfo
...@@ -211,10 +211,10 @@ LIMIT 1 ...@@ -211,10 +211,10 @@ LIMIT 1
// LatestDeposit returns the block number of the latest deposit known to the // LatestDeposit returns the block number of the latest deposit known to the
// database. // database.
func (d *Database) LatestDeposit() (*int64, error) { func (d *Database) LatestDeposit() (*uint64, error) {
row := d.conn.QueryRow(latestDepositQuery) row := d.conn.QueryRow(latestDepositQuery)
var latestTransfer int64 var latestTransfer uint64
err := row.Scan(&latestTransfer) err := row.Scan(&latestTransfer)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, nil return nil, nil
...@@ -235,7 +235,7 @@ ORDER BY dep.id ASC ...@@ -235,7 +235,7 @@ ORDER BY dep.id ASC
// ConfirmedDeposits returns the set of all deposits that have sufficient // ConfirmedDeposits returns the set of all deposits that have sufficient
// confirmation, but do not have a recorded disbursement. // confirmation, but do not have a recorded disbursement.
func (d *Database) ConfirmedDeposits(blockNumber, confirmations int64) ([]Deposit, error) { func (d *Database) ConfirmedDeposits(blockNumber, confirmations uint64) ([]Deposit, error) {
rows, err := d.conn.Query(confirmedDepositsQuery, confirmations, blockNumber) rows, err := d.conn.Query(confirmedDepositsQuery, confirmations, blockNumber)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -287,9 +287,9 @@ SET (txn_hash, block_number, block_timestamp) = ($2, $3, $4) ...@@ -287,9 +287,9 @@ SET (txn_hash, block_number, block_timestamp) = ($2, $3, $4)
// UpsertDisbursement inserts a disbursement, or updates an existing record // UpsertDisbursement inserts a disbursement, or updates an existing record
// in-place if the ID already exists. // in-place if the ID already exists.
func (d *Database) UpsertDisbursement( func (d *Database) UpsertDisbursement(
id int64, id uint64,
txnHash common.Hash, txnHash common.Hash,
blockNumber int64, blockNumber uint64,
blockTimestamp time.Time, blockTimestamp time.Time,
) error { ) error {
if blockTimestamp.IsZero() { if blockTimestamp.IsZero() {
......
...@@ -93,10 +93,10 @@ func TestLatestDeposit(t *testing.T) { ...@@ -93,10 +93,10 @@ func TestLatestDeposit(t *testing.T) {
// Query should return nil on empty databse. // Query should return nil on empty databse.
latestDeposit, err := d.LatestDeposit() latestDeposit, err := d.LatestDeposit()
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, (*int64)(nil), latestDeposit) require.Equal(t, (*uint64)(nil), latestDeposit)
// Update table to have a single element. // Update table to have a single element.
expLatestDeposit := int64(1) expLatestDeposit := uint64(1)
err = d.UpsertDeposits([]db.Deposit{{ err = d.UpsertDeposits([]db.Deposit{{
ID: 1, ID: 1,
TxnHash: common.HexToHash("0xf1"), TxnHash: common.HexToHash("0xf1"),
...@@ -249,9 +249,9 @@ func TestUpsertDisbursement(t *testing.T) { ...@@ -249,9 +249,9 @@ func TestUpsertDisbursement(t *testing.T) {
address := common.HexToAddress("0xaa01") address := common.HexToAddress("0xaa01")
amount := big.NewInt(1) amount := big.NewInt(1)
depTxnHash := common.HexToHash("0xdd01") depTxnHash := common.HexToHash("0xdd01")
depBlockNumber := int64(1) depBlockNumber := uint64(1)
disTxnHash := common.HexToHash("0xee02") disTxnHash := common.HexToHash("0xee02")
disBlockNumber := int64(2) disBlockNumber := uint64(2)
// Calling UpsertDisbursement with the zero timestamp should fail. // Calling UpsertDisbursement with the zero timestamp should fail.
err := d.UpsertDisbursement(0, common.HexToHash("0xdd00"), 0, time.Time{}) err := d.UpsertDisbursement(0, common.HexToHash("0xdd00"), 0, time.Time{})
......
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