Skip to content

Commit

Permalink
Merge branch 'fix' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenson080 committed Oct 16, 2024
2 parents 7221425 + 90a8f17 commit 1aeae65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend-wbtc/src/routes/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default (): Resource => ({
try {
const { fromBridgeAddress, toBridgeAssistAddress, fromChain, fromUser, index } =
req.query

console.log(fromBridgeAddress, toBridgeAssistAddress, fromBridgeAddress, fromChain, index, 'tracking param')
if (!fromBridgeAddress)
return res.status(400).send('fromBridgeAddress not specified')
if (!toBridgeAssistAddress)
Expand Down
17 changes: 16 additions & 1 deletion backend-wbtc/src/services/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const getWalletEVM = () => new Wallet(process.env.PRIVATE_KEY!)

const getWallet = (signerIndex: number) => {
if (signerIndex === 0) {
console.log(process.env.PRIVATE_KEY, signerIndex, 'pk')
return new Wallet(process.env.PRIVATE_KEY, getProvider(config.DEFAULT_CHAINID))
}
return new Wallet(process.env.PRIVATE_KEY2!, getProvider(config.DEFAULT_CHAINID))
Expand All @@ -26,6 +27,7 @@ async function signHashedTransaction(
signerIndex: number
) {
const wallet = getWallet(signerIndex)
console.log('sign hash', wallet, signerIndex)
const domain = {
name: EIP712DOMAIN_NAME,
version: EIP712DOMAIN_VERSION,
Expand All @@ -35,8 +37,9 @@ async function signHashedTransaction(
const types = {
[eip712Transaction.name]: eip712Transaction.fields,
}

console.log('sign hash 2', domain)
const sign = await wallet._signTypedData(domain, types, transaction)
console.log('sign hash 3', sign)
return sign
}

Expand All @@ -58,25 +61,36 @@ export const signTransaction = async (
index: string
) => {
let tx: TransactionContract
console.log('helllo1')
if (fromChain.startsWith('evm.')) {
console.log('helllo2')
const { bridgeAssist } = useContracts(undefined, fromChain.slice(4) as ChainId)
console.log('helllo3', bridgeAssist)
tx = await bridgeAssist(fromBridgeAddress).transactions(fromUser, index)
console.log('helllo4', tx)
} else {
throw Error('bad arguments')
}
console.log('helllo5')
const provider = getProvider(fromChain.slice(4) as ChainId)
console.log('helllo6')
const currentBlock = await safeRead(provider.getBlockNumber(), 0)
console.log('helllo7', currentBlock)
if (currentBlock === 0 || tx.block.gt(currentBlock))
throw Error('waiting for confirmations')
console.log('helllo8')
if (tx.toChain.startsWith('evm.')) {
console.log('helllo9')
const chainId = tx.toChain.replace('evm.', '')
console.log('helllo10', chainId)
let signatures = []
const signer0 = await signHashedTransaction(
extractFulfillTransaction(tx),
chainId,
toBridgeAddress,
0
)
console.log('helllo11', signer0)
signatures.push(signer0)
if (process.env.PRIVATE_KEY2){
const signer1 = await signHashedTransaction(
Expand All @@ -87,6 +101,7 @@ export const signTransaction = async (
)
signatures.push(signer1)
}
console.log('helllo12', signatures)
return signatures
} else {
throw Error('bad contract params')
Expand Down

0 comments on commit 1aeae65

Please sign in to comment.