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 Sep 29, 2023
1 parent 5ad4b1d commit d779f3f
Show file tree
Hide file tree
Showing 3 changed files with 29 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)
}
}
3 changes: 3 additions & 0 deletions ironfish/src/rpc/routes/chain/getTransactionStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Note {
hash: string
value: string
memo: string
sender: string
}

interface Transaction {
Expand All @@ -49,6 +50,7 @@ const NoteSchema = yup
hash: yup.string().required(),
value: yup.string().required(),
memo: yup.string().required(),
sender: yup.string().required(),
})
.required()

Expand Down Expand Up @@ -141,6 +143,7 @@ routes.register<typeof GetTransactionStreamRequestSchema, GetTransactionStreamRe
assetId: decryptedNote.assetId().toString('hex'),
assetName: assetValue?.name.toString('hex') || '',
hash: decryptedNote.hash().toString('hex'),
sender: decryptedNote.sender(),
})
}
}
Expand Down
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 d779f3f

Please sign in to comment.