Refactor account creation auth endpoints

This commit is contained in:
Arnau B
2020-10-29 19:13:14 +01:00
parent 8c6f5f2950
commit 8c9d13ffa5
9 changed files with 316 additions and 165 deletions

View File

@@ -55,7 +55,7 @@ func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error
return err
}
// GetAccountCreationAuth returns an account creation authorization into the DB
// GetAccountCreationAuth returns an account creation authorization from the DB
func (l2db *L2DB) GetAccountCreationAuth(addr ethCommon.Address) (*common.AccountCreationAuth, error) {
auth := new(common.AccountCreationAuth)
return auth, meddler.QueryRow(
@@ -65,6 +65,16 @@ func (l2db *L2DB) GetAccountCreationAuth(addr ethCommon.Address) (*common.Accoun
)
}
// GetAccountCreationAuthAPI returns an account creation authorization from the DB
func (l2db *L2DB) GetAccountCreationAuthAPI(addr ethCommon.Address) (*AccountCreationAuthAPI, error) {
auth := new(AccountCreationAuthAPI)
return auth, meddler.QueryRow(
l2db.db, auth,
"SELECT * FROM account_creation_auth WHERE eth_addr = $1;",
addr,
)
}
// AddTx inserts a tx to the pool
func (l2db *L2DB) AddTx(tx *PoolL2TxWrite) error {
return meddler.Insert(l2db.db, "tx_pool", tx)

View File

@@ -114,3 +114,10 @@ func (tx PoolTxAPI) MarshalJSON() ([]byte, error) {
},
})
}
type AccountCreationAuthAPI struct {
EthAddr apitypes.HezEthAddr `json:"hezEthereumAddress" meddler:"eth_addr" `
BJJ apitypes.HezBJJ `json:"bjj" meddler:"bjj" `
Signature apitypes.EthSignature `json:"signature" meddler:"signature" `
Timestamp time.Time `json:"timestamp" meddler:"timestamp,utctime"`
}