-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into return-zero-in-max-functions
- Loading branch information
Showing
10 changed files
with
292 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
Address, | ||
ethereum, | ||
crypto, | ||
ByteArray, | ||
BigInt, | ||
Bytes, | ||
dataSource, | ||
} from "@graphprotocol/graph-ts" | ||
|
||
const DEPOSIT_REVEALED_EVENT_SIGNATURE = crypto.keccak256( | ||
ByteArray.fromUTF8( | ||
"DepositRevealed(bytes32,uint32,address,uint64,bytes8,bytes20,bytes20,bytes4,address)", | ||
), | ||
) | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function findBitcoinTransactionIdFromTransactionReceipt( | ||
transactionReceipt: ethereum.TransactionReceipt | null, | ||
): string { | ||
const tbtcV2BridgeAddress = Address.fromBytes( | ||
dataSource.context().getBytes("tbtcBridgeAddress"), | ||
) | ||
|
||
if (!transactionReceipt) { | ||
throw new Error("Transaction receipt not available") | ||
} | ||
|
||
// We must cast manually to `ethereum.TransactionReceipt` otherwise | ||
// AssemblyScript will fail. | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const receipt = transactionReceipt as ethereum.TransactionReceipt | ||
|
||
let depositRevealedLogIndex = -1 | ||
for (let i = 0; i < receipt.logs.length; i += 1) { | ||
const receiptLog = receipt.logs[i] | ||
|
||
if ( | ||
receiptLog.address.equals(tbtcV2BridgeAddress) && | ||
receiptLog.topics[0].equals(DEPOSIT_REVEALED_EVENT_SIGNATURE) | ||
) { | ||
depositRevealedLogIndex = i | ||
} | ||
} | ||
|
||
if (depositRevealedLogIndex < 0) { | ||
throw new Error("Cannot find `DepositRevealed` event in transaction logs") | ||
} | ||
|
||
const depositRevealedLog = receipt.logs[depositRevealedLogIndex] | ||
|
||
// Bitcoin transaction hash in little-endian byte order. The first 32 bytes | ||
// (w/o `0x` prefix) points to the Bitcoin transaction hash. | ||
const bitcoinTxHash = depositRevealedLog.data.toHexString().slice(2, 66) | ||
|
||
// Bitcoin transaction id in the same byte order as used by the | ||
// Bitcoin block explorers. | ||
const bitcoinTransactionId = BigInt.fromUnsignedBytes( | ||
Bytes.fromHexString(bitcoinTxHash), | ||
) | ||
.toHexString() | ||
.slice(2) | ||
|
||
return bitcoinTransactionId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.