Skip to content

Commit

Permalink
feat: add txid and vout to payout (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi authored Nov 26, 2024
1 parent 8c5cb11 commit 1d61fbf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions proto/api/bria.proto
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ message Payout {
string external_id = 7;
optional google.protobuf.Struct metadata = 8;
optional uint32 batch_inclusion_estimated_at = 11;
optional string tx_id = 12;
optional uint32 vout = 13;
}

message ListPayoutsResponse {
Expand Down
6 changes: 6 additions & 0 deletions src/api/server/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ impl From<PayoutWithInclusionEstimate> for proto::Payout {
}
};

let (tx_id, vout) = payout.outpoint.map_or((None, None), |outpoint| {
(Some(outpoint.txid.to_string()), Some(outpoint.vout))
});

let batch_inclusion_estimated_at =
estimated_batch_inclusion.map(|time| time.timestamp() as u32);
proto::Payout {
Expand All @@ -199,6 +203,8 @@ impl From<PayoutWithInclusionEstimate> for proto::Payout {
serde_json::from_value(json).expect("Could not transfer json -> struct")
}),
batch_inclusion_estimated_at,
tx_id,
vout,
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions tests/e2e/payout.bats
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ teardown_file() {

@test "payout: Creates a manually triggered payout-queue and triggers it" {
bria_address=$(bria_cmd new-address -w default | jq -r '.address')
bitcoin_cli -regtest sendtoaddress ${bria_address} 1
bitcoin_cli -regtest sendtoaddress ${bria_address} 1
bitcoin_cli -generate 10
bria_cmd create-payout-queue -n manual -m true
bria_cmd submit-payout --wallet default --queue-name manual --destination bcrt1q208tuy5rd3kvy8xdpv6yrczg7f3mnlk3lql7ej --amount 75000000

for i in {1..20}; do
for i in {1..20}; do
batch_id=$(bria_cmd list-payouts -w default | jq -r '.payouts[0].batchId')
[[ "${batch_id}" != "null" ]] && break;
sleep 1
Expand All @@ -166,12 +166,22 @@ teardown_file() {

bria_cmd trigger-payout-queue --name manual;

for i in {1..20}; do
batch_id=$(bria_cmd list-payouts -w default | jq -r '.payouts[0].batchId')
[[ "${batch_id}" != "null" ]] && break
for i in {1..20}; do
payout=$(bria_cmd list-payouts -w default | jq -r '.payouts[0]')
payout_id=$(echo ${payout} | jq -r '.id')
batch_id=$(echo ${payout} | jq -r '.batchId')
tx_id=$(echo ${payout} | jq -r '.txId')
vout=$(echo ${payout} | jq -r '.vout')
[[ "${batch_id}" != "null" && "${tx_id}" != "null" && "${vout}" != "null" ]] && break
sleep 1
done
[[ "${batch_id}" != "null" ]] || exit 1
[[ "${batch_id}" != "null" && "${tx_id}" != "null" && "${vout}" != "null" ]] || exit 1

payout=$(bria_cmd get-payout --id ${payout_id} | jq -r '.payout')
batch_id=$(echo ${payout} | jq -r '.batchId')
tx_id=$(echo ${payout} | jq -r '.txId')
vout=$(echo ${payout} | jq -r '.vout')
[[ "${batch_id}" != "null" && "${tx_id}" != "null" && "${vout}" != "null" ]] || exit 1

for i in {1..20}; do
cache_wallet_balance
Expand All @@ -182,7 +192,7 @@ teardown_file() {
[[ $(cached_pending_income) != 0 ]] || exit 1

bitcoin_cli -generate 2

for i in {1..20}; do
cache_wallet_balance
[[ $(cached_pending_income) == 0 ]] && break;
Expand Down

0 comments on commit 1d61fbf

Please sign in to comment.