From d779f3f3375e0dbf30c0d77cae04a080618f5bdf Mon Sep 17 00:00:00 2001 From: Hugh Cunningham <57735705+hughy@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:23:13 -0700 Subject: [PATCH] bridge relay triggers mints via API (#4322) updates the 'service:bridge:relay' command to invoke the 'bridge/send' API endpoint to trigger minting tokens on the destination chain calls 'bridge/send' only once per Iron Fish block to try to process blocks atomically adds 'sender' to each note in the response of 'chain/getTransactionStream' RPC so that we can pass the sender address to the bridge API for validation --- ironfish-cli/src/commands/service/bridge/relay.ts | 15 ++++++++++++--- .../src/rpc/routes/chain/getTransactionStream.ts | 3 +++ ironfish/src/webApi.ts | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ironfish-cli/src/commands/service/bridge/relay.ts b/ironfish-cli/src/commands/service/bridge/relay.ts index ab823d3ec6..c9ea59fdae 100644 --- a/ironfish-cli/src/commands/service/bridge/relay.ts +++ b/ironfish-cli/src/commands/service/bridge/relay.ts @@ -125,16 +125,25 @@ export default class BridgeRelay extends IronfishCommand { async commit(api: WebApi, response: GetTransactionStreamResponse): Promise { Assert.isNotUndefined(response) + const sends = [] + const transactions = response.transactions for (const transaction of transactions) { for (const note of transaction.notes) { - this.log(`Processing deposit ${note.memo}, from transaction ${transaction.hash}`) - // TODO: get Eth deposit address from API - // TODO: call Eth bridge contract to mint + this.log(`Received deposit ${note.memo} in transaction ${transaction.hash}`) + sends.push({ + id: note.memo, + amount: note.value, + asset: note.assetId, + source_address: note.sender, + source_transaction: transaction.hash, + }) } } + await api.sendBridgeDeposits(sends) + await api.setBridgeHead(response.block.hash) } } diff --git a/ironfish/src/rpc/routes/chain/getTransactionStream.ts b/ironfish/src/rpc/routes/chain/getTransactionStream.ts index eedfd315c7..eed9615b94 100644 --- a/ironfish/src/rpc/routes/chain/getTransactionStream.ts +++ b/ironfish/src/rpc/routes/chain/getTransactionStream.ts @@ -31,6 +31,7 @@ interface Note { hash: string value: string memo: string + sender: string } interface Transaction { @@ -49,6 +50,7 @@ const NoteSchema = yup hash: yup.string().required(), value: yup.string().required(), memo: yup.string().required(), + sender: yup.string().required(), }) .required() @@ -141,6 +143,7 @@ routes.register { + this.requireToken() + + await axios.post(`${this.host}/bridge/send`, { sends }, this.options()) + } + options(headers: Record = {}): AxiosRequestConfig { return { headers: {