Skip to content

Commit

Permalink
bridge relay triggers mints via API (#4322)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hughy authored and leanthebean committed Feb 5, 2024
1 parent 0a02f6b commit e76a551
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ironfish-cli/src/commands/service/bridge/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,25 @@ export default class BridgeRelay extends IronfishCommand {
async commit(api: WebApi, response: GetTransactionStreamResponse): Promise<void> {
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)
}
}
14 changes: 14 additions & 0 deletions ironfish/src/webApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ export class WebApi {
await axios.post(`${this.host}/bridge/head`, { head }, options)
}

async sendBridgeDeposits(
sends: {
id: string
amount: string
asset: string
source_address: string
source_transaction: string
}[],
): Promise<void> {
this.requireToken()

await axios.post(`${this.host}/bridge/send`, { sends }, this.options())
}

options(headers: Record<string, string> = {}): AxiosRequestConfig {
return {
headers: {
Expand Down

0 comments on commit e76a551

Please sign in to comment.