Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Fetch deposit BTC address (contract code) #25

Merged
merged 37 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3c6aa8f
Export initialiseDeposit, empty test
liamzebedee Aug 1, 2019
7069859
Implement getDepositBTCPublicKey and test
liamzebedee Aug 1, 2019
bbcf7d7
Now converting key to BTC address
liamzebedee Aug 2, 2019
2d82278
Merge artifact addresses
liamzebedee Aug 5, 2019
10a57fa
Simpler try/catch
liamzebedee Aug 5, 2019
9ce980f
Doc getDepositBTCPublicKey
liamzebedee Aug 5, 2019
328bc85
Doc watchForDepositBTCPublicKey
liamzebedee Aug 5, 2019
3982aad
Add type to param doc
liamzebedee Aug 5, 2019
cda8d02
Merge master
liamzebedee Aug 5, 2019
f9a1350
Manual linting
liamzebedee Aug 6, 2019
511bcd2
Refactor getDepositBtcAddress
liamzebedee Aug 6, 2019
cdb5023
Better self-doc'ing code for hex values in events
liamzebedee Aug 6, 2019
e6e238e
Refactor test to match new names
liamzebedee Aug 6, 2019
51b586f
Clearer comments
liamzebedee Aug 6, 2019
339f449
Comments on error handling
liamzebedee Aug 6, 2019
5d07f3d
Merge from master
liamzebedee Aug 6, 2019
801c02c
Organise imports
liamzebedee Aug 6, 2019
62beb66
Remove redundant code
liamzebedee Aug 6, 2019
d021252
Fix doc format
liamzebedee Aug 6, 2019
567c7d2
Remove artifacts
liamzebedee Aug 6, 2019
009551e
Merge from master
liamzebedee Aug 6, 2019
013eca2
Fix import path
liamzebedee Aug 6, 2019
22babe9
Make index.js the main import
liamzebedee Aug 6, 2019
bfda437
Test path issues with CI build
liamzebedee Aug 6, 2019
d5819d3
Move back index.js to avoid test refactoring
liamzebedee Aug 6, 2019
030b620
Add Address back to imports
nkuba Aug 6, 2019
4e327d0
Consistent export syntax
liamzebedee Aug 6, 2019
729aa1e
Remove tbtc-helpers, use standard path for index.js
liamzebedee Aug 6, 2019
d6485e5
Revert export changes
liamzebedee Aug 6, 2019
3166d45
Remove index.js, import with simple paths
liamzebedee Aug 6, 2019
37a4c6f
Fix bitcoinspv import
liamzebedee Aug 6, 2019
fc5d82e
Add index.js, again
liamzebedee Aug 6, 2019
cb2b709
Fix import syntax
liamzebedee Aug 6, 2019
d1d5288
Another permutation of "main" and import path
liamzebedee Aug 6, 2019
93230da
Add max-old-space-size to build command
nkuba Aug 7, 2019
b9df389
Merge remote-tracking branch 'origin/master' into put-down-small-bond
nkuba Aug 7, 2019
a680bec
Fix exports in FundingTransaction
nkuba Aug 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions client/src/Deposit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
TBTCSystem,
TBTCToken,
KeepBridge,
DepositFactory
} from './eth/contracts'
import { DepositFactory, KeepBridge, TBTCSystem, TBTCToken } from './eth/contracts';

/**
* Creates a new deposit and returns its address
Expand Down Expand Up @@ -32,6 +27,5 @@ export async function createDeposit() {
})

const depositAddress = logs[0].args.depositCloneAddress

return depositAddress
}
67 changes: 55 additions & 12 deletions client/src/FundingTransaction.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,67 @@
// 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
import { Network, publicKeyToP2WPKHaddress } from 'tbtc-helpers/src/Address';
import { Deposit, TBTCSystem } from './eth/contracts';

/**
* 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
}

// Transition from PAGE 3 to PAGE 4
// 1. Wait for transaction on chain
// 2. Return transaction ID
async function getFundingTransactionID(electrumConfig, bitcoinAddress) {
export async function getFundingTransactionID(electrumConfig, bitcoinAddress) {
// TODO: Implement
}

// 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, getFundingTransactionID, waitForConfirmations,
}
}
Loading