Skip to content

Commit

Permalink
Api 01.1.11 (#1229)
Browse files Browse the repository at this point in the history
* ignore transaction parse errors

* fix error message
  • Loading branch information
alistair-singh authored Jun 12, 2024
1 parent 6bb4c8a commit 06122ae
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 86 deletions.
2 changes: 1 addition & 1 deletion web/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/api",
"version": "0.1.10",
"version": "0.1.11",
"description": "Snowbridge API client",
"license": "Apache-2.0",
"repository": {
Expand Down
138 changes: 74 additions & 64 deletions web/packages/api/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,74 +908,84 @@ const getEthOutboundMessages = async (
om.getBlock(),
context.ethereum.api.getTransaction(om.transactionHash),
])
const [
tokenAddress,
destinationParachain,
[addressType, beneficiaryAddress],
destinationFee,
amount,
] = context.ethereum.contracts.gateway.interface.decodeFunctionData(
"sendToken",
transaction!.data
)
let beneficiary = beneficiaryAddress as string
switch (addressType) {
case 0n:
{
// 4-byte index
const index = BigInt(beneficiary.substring(0, 6))
beneficiary = index.toString()
}
break
case 2n:
{
// 20-byte address
beneficiary = beneficiary.substring(0, 42)
}
break
}

let beaconBlockRoot
if (!skipLightClientUpdates) {
try {
beaconBlockRoot = await fetchBeaconSlot(
context.config.ethereum.beacon_url,
block.parentBeaconBlockRoot as any
)
} catch (err) {
let message = "Unknown"
if (err instanceof Error) {
message = err.message
try {
const [
tokenAddress,
destinationParachain,
[addressType, beneficiaryAddress],
destinationFee,
amount,
] = context.ethereum.contracts.gateway.interface.decodeFunctionData(
"sendToken",
transaction!.data
)
let beneficiary = beneficiaryAddress as string
switch (addressType) {
case 0n:
{
// 4-byte index
const index = BigInt(beneficiary.substring(0, 6))
beneficiary = index.toString()
}
break
case 2n:
{
// 20-byte address
beneficiary = beneficiary.substring(0, 42)
}
break
}

let beaconBlockRoot
if (!skipLightClientUpdates) {
try {
beaconBlockRoot = await fetchBeaconSlot(
context.config.ethereum.beacon_url,
block.parentBeaconBlockRoot as any
)
} catch (err) {
let message = "Unknown"
if (err instanceof Error) {
message = err.message
}
console.error(
`Error fetching beacon slot: ${message}. Skipping light client update.`,
err
)
}
console.error(
`Error fetching beacon slot: ${message}. Skipping light client update.`,
err
)
}
}

result.push({
blockNumber: om.blockNumber,
blockHash: om.blockHash,
logIndex: om.index,
transactionIndex: om.transactionIndex,
transactionHash: om.transactionHash,
data: {
sourceAddress: transaction!.from,
timestamp: block.timestamp,
channelId: om.args.channelID,
nonce: Number(om.args.nonce),
messageId: om.args.messageID,
parentBeaconSlot: beaconBlockRoot
? Number(beaconBlockRoot.data.message.slot)
: undefined,
tokenAddress: tokenAddress as string,
destinationParachain: Number(destinationParachain),
beneficiaryAddress: beneficiary,
destinationFee: destinationFee.toString() as string,
amount: amount.toString() as string,
},
})
result.push({
blockNumber: om.blockNumber,
blockHash: om.blockHash,
logIndex: om.index,
transactionIndex: om.transactionIndex,
transactionHash: om.transactionHash,
data: {
sourceAddress: transaction!.from,
timestamp: block.timestamp,
channelId: om.args.channelID,
nonce: Number(om.args.nonce),
messageId: om.args.messageID,
parentBeaconSlot: beaconBlockRoot
? Number(beaconBlockRoot.data.message.slot)
: undefined,
tokenAddress: tokenAddress as string,
destinationParachain: Number(destinationParachain),
beneficiaryAddress: beneficiary,
destinationFee: destinationFee.toString() as string,
amount: amount.toString() as string,
},
})
} catch (err) {
let message = "Transaction decoding error"
if (err instanceof Error) {
message = `Transaction decoding error: ${err.message}`
}
console.error("Skipping message: ", message)
continue
}
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion web/packages/contract-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contract-types",
"version": "0.1.10",
"version": "0.1.11",
"description": "Snowbridge contract type bindings",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contracts",
"version": "0.1.10",
"version": "0.1.11",
"description": "Snowbridge contract source and abi.",
"license": "Apache-2.0",
"repository": {
Expand Down
36 changes: 17 additions & 19 deletions web/packages/operations/src/global_transfer_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@ const monitor = async () => {
if (!config.SUBSCAN_API) throw Error(`Environment ${env} does not support subscan.`)

const ethereumProvider = new AlchemyProvider("sepolia", process.env.REACT_APP_ALCHEMY_KEY)
const context = await contextFactory(
{
ethereum: {
execution_url: ethereumProvider,
beacon_url: config.BEACON_HTTP_API,
const context = await contextFactory({
ethereum: {
execution_url: ethereumProvider,
beacon_url: config.BEACON_HTTP_API,
},
polkadot: {
url: {
bridgeHub: config.BRIDGE_HUB_WS_URL,
assetHub: config.ASSET_HUB_WS_URL,
relaychain: config.RELAY_CHAIN_WS_URL,
parachains: config.PARACHAINS,
},
polkadot: {
url: {
bridgeHub: config.BRIDGE_HUB_WS_URL,
assetHub: config.ASSET_HUB_WS_URL,
relaychain: config.RELAY_CHAIN_WS_URL,
parachains: config.PARACHAINS,
},
},
appContracts: {
gateway: config.GATEWAY_CONTRACT,
beefy: config.BEEFY_CONTRACT,
},
}
)
},
appContracts: {
gateway: config.GATEWAY_CONTRACT,
beefy: config.BEEFY_CONTRACT,
},
})

const ethBlockTimeSeconds = 12
const polkadotBlockTimeSeconds = 9
Expand Down

0 comments on commit 06122ae

Please sign in to comment.