This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Fetch deposit BTC address (contract code) #25
Merged
Merged
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3c6aa8f
Export initialiseDeposit, empty test
liamzebedee 7069859
Implement getDepositBTCPublicKey and test
liamzebedee bbcf7d7
Now converting key to BTC address
liamzebedee 2d82278
Merge artifact addresses
liamzebedee 10a57fa
Simpler try/catch
liamzebedee 9ce980f
Doc getDepositBTCPublicKey
liamzebedee 328bc85
Doc watchForDepositBTCPublicKey
liamzebedee 3982aad
Add type to param doc
liamzebedee cda8d02
Merge master
liamzebedee f9a1350
Manual linting
liamzebedee 511bcd2
Refactor getDepositBtcAddress
liamzebedee cdb5023
Better self-doc'ing code for hex values in events
liamzebedee e6e238e
Refactor test to match new names
liamzebedee 51b586f
Clearer comments
liamzebedee 339f449
Comments on error handling
liamzebedee 5d07f3d
Merge from master
liamzebedee 801c02c
Organise imports
liamzebedee 62beb66
Remove redundant code
liamzebedee d021252
Fix doc format
liamzebedee 567c7d2
Remove artifacts
liamzebedee 009551e
Merge from master
liamzebedee 013eca2
Fix import path
liamzebedee 22babe9
Make index.js the main import
liamzebedee bfda437
Test path issues with CI build
liamzebedee d5819d3
Move back index.js to avoid test refactoring
liamzebedee 030b620
Add Address back to imports
nkuba 4e327d0
Consistent export syntax
liamzebedee 729aa1e
Remove tbtc-helpers, use standard path for index.js
liamzebedee d6485e5
Revert export changes
liamzebedee 3166d45
Remove index.js, import with simple paths
liamzebedee 37a4c6f
Fix bitcoinspv import
liamzebedee fc5d82e
Add index.js, again
liamzebedee cb2b709
Fix import syntax
liamzebedee d1d5288
Another permutation of "main" and import path
liamzebedee 93230da
Add max-old-space-size to build command
nkuba b9df389
Merge remote-tracking branch 'origin/master' into put-down-small-bond
nkuba a680bec
Fix exports in FundingTransaction
nkuba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,61 @@ | ||
const Address = require('tbtc-helpers').Address | ||
import { Network, publicKeyToP2WPKHaddress } from 'tbtc-helpers' | ||
import { Deposit, TBTCSystem } from './eth/contracts' | ||
|
||
// PAGE 3: Pay BTC | ||
async function getAddress(depositAddress) { | ||
// TODO: Implement: | ||
// 1. Get keep public key from the deposit | ||
// 2. Calculate P2WPKH address from the key | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So many blank lines, let's remove them in one of the upcoming PRs. |
||
|
||
|
||
/** | ||
* Requests a Bitcoin public key for a Deposit and returns it as a Bitcoin address | ||
* @param {string} depositAddress the address of a Deposit contract | ||
* @return {string} a bech32-encoded Bitcoin address, generated from a SegWit P2WPKH script | ||
*/ | ||
export async function getDepositBtcAddress(depositAddress) { | ||
const tbtcSystem = await TBTCSystem.deployed() | ||
|
||
// 1. Request public key from the deposit | ||
const deposit = await Deposit.at(depositAddress) | ||
|
||
console.log(`Call getPublicKey for deposit [${deposit.address}]`) | ||
|
||
await deposit.retrieveSignerPubkey() | ||
.catch((err) => { | ||
// This can happen when the public key was already retrieved before | ||
// and we may succeed to get it with tbtcSystem.getPastEvents in the following lines | ||
// TODO: there may be other errors that this allows to pass, refactor in future | ||
console.error(`retrieveSignerPubkey failed: ${err}`) | ||
}) | ||
|
||
// 2. Parse the logs to get the public key | ||
// since the public key event is emitted in another contract, we | ||
// can't get this from result.logs | ||
const eventList = await tbtcSystem.getPastEvents( | ||
'RegisteredPubkey', | ||
{ | ||
fromBlock: '0', | ||
toBlock: 'latest', | ||
filter: { _depositContractAddress: depositAddress } | ||
} | ||
) | ||
|
||
if (eventList.length == 0) { | ||
throw new Error(`couldn't find RegisteredPubkey event for deposit address: ${depositAddress}`) | ||
} | ||
|
||
let publicKeyX = eventList[0].args._signingGroupPubkeyX | ||
let publicKeyY = eventList[0].args._signingGroupPubkeyY | ||
publicKeyX = publicKeyX.replace('0x', '') | ||
publicKeyY = publicKeyY.replace('0x', '') | ||
|
||
console.log(`Registered public key for deposit ${depositAddress}:\nX: ${publicKeyX}\nY: ${publicKeyY}`) | ||
|
||
const btcAddress = publicKeyToP2WPKHaddress( | ||
`${publicKeyX}${publicKeyY}`, | ||
Network.testnet | ||
) | ||
return btcAddress | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here about blank lines. |
||
/** | ||
* Funding transaction details. | ||
* @typedef FundingTransaction | ||
|
@@ -23,12 +72,12 @@ async function getAddress(depositAddress) { | |
* @param {number} expectedValue Expected transaction output value (satoshis). | ||
* @return {FundingTransaction} Transaction details. | ||
*/ | ||
async function watchForFundingTransaction(electrumClient, bitcoinAddress, expectedValue) { | ||
export async function watchForFundingTransaction(electrumClient, bitcoinAddress, expectedValue) { | ||
const script = Address.addressToScript(bitcoinAddress) | ||
|
||
// This function is used as a callback to electrum client. It is invoked when | ||
// am existing or a new transaction is found. | ||
const findFundingTransaction = async function(status) { | ||
const findFundingTransaction = async function (status) { | ||
// Check if status is null which means there are not transactions for the | ||
// script. | ||
if (status == null) { | ||
|
@@ -62,12 +111,8 @@ async function watchForFundingTransaction(electrumClient, bitcoinAddress, expect | |
} | ||
|
||
// PAGE 4. WAITING FOR CONFIRMATIONS | ||
async function waitForConfirmations(transactionID) { | ||
export async function waitForConfirmations(transactionID) { | ||
// TODO: Implement: | ||
// 1. Wait for required number of confirmations for the transaction | ||
// 2. Monitor confirmations on the chain and return when ready | ||
} | ||
|
||
module.exports = { | ||
getAddress, watchForFundingTransaction, waitForConfirmations, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './Deposit' | ||
export * from './FundingTransaction' | ||
export * from './eth/contracts' |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"redux": "^4.0.4", | ||
"redux-saga": "^1.0.5", | ||
"tbtc-client": "file:client", | ||
"tbtc-helpers": "file:lib/tbtc-helpers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this dependency in dapp's |
||
"truffle": "^5.0.29", | ||
"truffle-contract": "^4.0.26", | ||
"web3": "^1.2.0" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is failing because of this removal.