-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: New vault swap encoding RPC & bouncer test #5384
Merged
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6401c48
feat: new vault swap encoding rpc
j4m1ef0rd 8d9ff2a
test: Btc vault swap bouncer test
j4m1ef0rd 29ce9ad
Merge branch 'main' into feat/vault-swap-rpc
j4m1ef0rd 58dbf09
refactor: address some PR comments
j4m1ef0rd 5e2870e
chore: rename bouncer evm vault swap file
j4m1ef0rd 124e5e1
feat: RPC in broker api and address some PR comments
j4m1ef0rd cd57633
Merge branch 'main' into feat/vault-swap-rpc
j4m1ef0rd 9b304ab
refactor: go back to better error types on encoded address
j4m1ef0rd c00685e
Merge branch 'main' into feat/vault-swap-rpc
j4m1ef0rd e2327ca
chore: change prewitness origin logic get test to pass
j4m1ef0rd bf8460c
chore: Address PR comments for bouncer test
j4m1ef0rd 3399d75
chore: use BlockNumber instead of u32 for retry duration
j4m1ef0rd e16a110
feat: simplified error handling
dandanlen 3422e8a
fix: pass-through base_rpc
dandanlen afc539c
feat: use direct access to node rpcs
dandanlen c8f64dc
chore: remove options
dandanlen 611ce46
fix: simplify bitcoin address return type
dandanlen 6a6d84e
fix: comments + clippy
dandanlen 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
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 |
---|---|---|
@@ -1,30 +1,55 @@ | ||
import Client from 'bitcoin-core'; | ||
import { sleep, btcClientMutex } from './utils'; | ||
|
||
export async function sendBtc(address: string, amount: number | string) { | ||
const BTC_ENDPOINT = process.env.BTC_ENDPOINT || 'http://127.0.0.1:8332'; | ||
const client = new Client({ | ||
host: BTC_ENDPOINT.split(':')[1].slice(2), | ||
port: Number(BTC_ENDPOINT.split(':')[2]), | ||
username: 'flip', | ||
password: 'flip', | ||
wallet: 'whale', | ||
}); | ||
export const BTC_ENDPOINT = process.env.BTC_ENDPOINT || 'http://127.0.0.1:8332'; | ||
|
||
// Btc client has a limit on the number of concurrent requests | ||
const txid = await btcClientMutex.runExclusive(async () => | ||
client.sendToAddress(address, amount, '', '', false, true, null, 'unset', null, 1), | ||
); | ||
export const btcClient = new Client({ | ||
host: BTC_ENDPOINT.split(':')[1].slice(2), | ||
port: Number(BTC_ENDPOINT.split(':')[2]), | ||
username: 'flip', | ||
password: 'flip', | ||
wallet: 'whale', | ||
}); | ||
|
||
for (let i = 0; i < 50; i++) { | ||
const transactionDetails = await client.getTransaction(txid); | ||
export async function selectInputs(amount: number) { | ||
// List unspent UTXOs | ||
const utxos = await btcClient.listUnspent(); | ||
|
||
// Find a UTXO with enough funds | ||
const utxo = utxos.find((u) => u.amount >= amount); | ||
if (!utxo) throw new Error('Insufficient funds'); | ||
// TODO: be able to select more than one UTXO | ||
|
||
const change = utxo.amount - amount; | ||
|
||
// Prepare the transaction inputs and outputs | ||
const inputs = [ | ||
{ | ||
txid: utxo.txid, | ||
vout: utxo.vout, | ||
}, | ||
]; | ||
|
||
return { inputs, change }; | ||
} | ||
|
||
const confirmations = transactionDetails.confirmations; | ||
export async function waitForBtcTransaction(txid: string, confirmations = 1) { | ||
for (let i = 0; i < 50; i++) { | ||
const transactionDetails = await btcClient.getTransaction(txid); | ||
|
||
if (confirmations < 1) { | ||
if (transactionDetails.confirmations < confirmations) { | ||
await sleep(1000); | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
export async function sendBtc(address: string, amount: number | string) { | ||
// Btc client has a limit on the number of concurrent requests | ||
const txid = (await btcClientMutex.runExclusive(async () => | ||
btcClient.sendToAddress(address, amount, '', '', false, true, null, 'unset', null, 1), | ||
)) as string; | ||
|
||
await waitForBtcTransaction(txid); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
I think we want to keep this in the broker api, and pass it through to the custom rpc.