Skip to content

Commit c528143

Browse files
authored
Rename FFI bitcoin structs and specify units (#1537)
2 parents 3dc6aed + 55b5e01 commit c528143

10 files changed

Lines changed: 124 additions & 129 deletions

File tree

payjoin-ffi/csharp/IntegrationTests.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public bool Callback(byte[] script)
132132

133133
private sealed class CheckInputsNotSeenCallback : IsOutputKnown
134134
{
135-
public bool Callback(PlainOutPoint _outpoint) => false;
135+
public bool Callback(OutPoint _outpoint) => false;
136136
}
137137

138138
private sealed class ProcessPsbtCallback : ProcessPsbt
@@ -167,14 +167,14 @@ private static InputPair[] GetInputs(RpcClient rpc)
167167
var amountBtc = utxo.GetProperty("amount").GetDouble();
168168
var valueSat = (ulong)Math.Round(amountBtc * 100_000_000.0);
169169

170-
var txin = new PlainTxIn(
171-
new PlainOutPoint(txid, vout),
170+
var txin = new TxIn(
171+
new OutPoint(txid, vout),
172172
Array.Empty<byte>(),
173173
0,
174174
Array.Empty<byte[]>());
175175

176-
var txout = new PlainTxOut(valueSat, Convert.FromHexString(scriptPubKeyHex));
177-
var psbtIn = new PlainPsbtInput(txout, null, null);
176+
var txout = new TxOut(valueSat, Convert.FromHexString(scriptPubKeyHex));
177+
var psbtIn = new PsbtInput(txout, null, null);
178178

179179
inputs.Add(new InputPair(txin, psbtIn, null));
180180
}
@@ -364,14 +364,14 @@ public void TestFfiValidation()
364364
var invalidTxid = new string('0', 128);
365365
Assert.Throws<InputPairException.InvalidOutPoint>(() =>
366366
{
367-
var txin = new PlainTxIn(
368-
new PlainOutPoint(invalidTxid, 0),
367+
var txin = new TxIn(
368+
new OutPoint(invalidTxid, 0),
369369
Array.Empty<byte>(),
370370
0,
371371
Array.Empty<byte[]>()
372372
);
373-
var psbtIn = new PlainPsbtInput(
374-
new PlainTxOut(tooLargeAmount, new byte[] { 0x6a }),
373+
var psbtIn = new PsbtInput(
374+
new TxOut(tooLargeAmount, new byte[] { 0x6a }),
375375
null,
376376
null
377377
);
@@ -381,14 +381,14 @@ public void TestFfiValidation()
381381
var validTxid = new string('0', 64);
382382
var amountOutOfRange = Assert.Throws<InputPairException.FfiValidation>(() =>
383383
{
384-
var txin = new PlainTxIn(
385-
new PlainOutPoint(validTxid, 0),
384+
var txin = new TxIn(
385+
new OutPoint(validTxid, 0),
386386
Array.Empty<byte>(),
387387
0,
388388
Array.Empty<byte[]>()
389389
);
390-
var psbtIn = new PlainPsbtInput(
391-
new PlainTxOut(tooLargeAmount, new byte[] { 0x6a }),
390+
var psbtIn = new PsbtInput(
391+
new TxOut(tooLargeAmount, new byte[] { 0x6a }),
392392
null,
393393
null
394394
);
@@ -400,14 +400,14 @@ public void TestFfiValidation()
400400
Array.Fill(hugeScript, (byte)0x51);
401401
var scriptTooLarge = Assert.Throws<InputPairException.FfiValidation>(() =>
402402
{
403-
var txin = new PlainTxIn(
404-
new PlainOutPoint(validTxid, 0),
403+
var txin = new TxIn(
404+
new OutPoint(validTxid, 0),
405405
Array.Empty<byte>(),
406406
0,
407407
Array.Empty<byte[]>()
408408
);
409-
var psbtIn = new PlainPsbtInput(
410-
new PlainTxOut(1, hugeScript),
409+
var psbtIn = new PsbtInput(
410+
new TxOut(1, hugeScript),
411411
null,
412412
null
413413
);
@@ -417,18 +417,18 @@ public void TestFfiValidation()
417417

418418
var weightOutOfRange = Assert.Throws<InputPairException.FfiValidation>(() =>
419419
{
420-
var txin = new PlainTxIn(
421-
new PlainOutPoint(validTxid, 0),
420+
var txin = new TxIn(
421+
new OutPoint(validTxid, 0),
422422
Array.Empty<byte>(),
423423
0,
424424
Array.Empty<byte[]>()
425425
);
426-
var psbtIn = new PlainPsbtInput(
427-
new PlainTxOut(1, new byte[] { 0x6a }),
426+
var psbtIn = new PsbtInput(
427+
new TxOut(1, new byte[] { 0x6a }),
428428
null,
429429
null
430430
);
431-
new InputPair(txin, psbtIn, new PlainWeight(0));
431+
new InputPair(txin, psbtIn, new Weight(0));
432432
});
433433
Assert.IsType<FfiValidationException.WeightOutOfRange>(weightOutOfRange.v1);
434434

payjoin-ffi/csharp/UnitTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ public void InputPairRejectsInvalidOutpoint()
370370
{
371371
Assert.Throws<InputPairException.InvalidOutPoint>(() =>
372372
{
373-
var txin = new PlainTxIn(
374-
new PlainOutPoint("deadbeef", 0),
373+
var txin = new TxIn(
374+
new OutPoint("deadbeef", 0),
375375
new byte[] {},
376376
0,
377377
new byte[][] {}
378378
);
379-
var psbtIn = new PlainPsbtInput(null, null, null);
379+
var psbtIn = new PsbtInput(null, null, null);
380380
new InputPair(txin, psbtIn, null);
381381
});
382382
}

payjoin-ffi/dart/test/test_payjoin_integration_test.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ List<payjoin.InputPair> get_inputs(payjoin.RpcClient rpc_connection) {
222222
final amountBtc = utxo["amount"] as num;
223223
final amountSat = (amountBtc * 100000000).round();
224224

225-
final txin = payjoin.PlainTxIn(
226-
previousOutput: payjoin.PlainOutPoint(txid: txid, vout: vout),
225+
final txin = payjoin.TxIn(
226+
previousOutput: payjoin.OutPoint(txid: txid, vout: vout),
227227
scriptSig: Uint8List(0),
228228
sequence: 0,
229229
witness: <Uint8List>[],
230230
);
231-
final witnessUtxo = payjoin.PlainTxOut(
231+
final witnessUtxo = payjoin.TxOut(
232232
valueSat: amountSat,
233233
scriptPubkey: scriptPubKey,
234234
);
235-
final psbt_in = payjoin.PlainPsbtInput(
235+
final psbt_in = payjoin.PsbtInput(
236236
witnessUtxo: witnessUtxo,
237237
redeemScript: null,
238238
witnessScript: null,
@@ -322,7 +322,7 @@ Future<payjoin.PayjoinProposalReceiveSession> process_unchecked_proposal(
322322
) async {
323323
final unchecked_proposal = proposal
324324
.checkBroadcastSuitability(
325-
minFeeRate: null,
325+
minFeeRateSatPerKwu: null,
326326
canBroadcast: MempoolAcceptanceCallback(receiver),
327327
)
328328
.save(persister: recv_persister);
@@ -438,14 +438,14 @@ void main() {
438438
test('FFI validation', () async {
439439
final tooLargeAmount = 21000000 * 100000000 + 1;
440440
// Invalid outpoint should fail before amount checks.
441-
final txinInvalid = payjoin.PlainTxIn(
442-
previousOutput: payjoin.PlainOutPoint(txid: "00" * 64, vout: 0),
441+
final txinInvalid = payjoin.TxIn(
442+
previousOutput: payjoin.OutPoint(txid: "00" * 64, vout: 0),
443443
scriptSig: Uint8List(0),
444444
sequence: 0,
445445
witness: <Uint8List>[],
446446
);
447-
final psbtInDummy = payjoin.PlainPsbtInput(
448-
witnessUtxo: payjoin.PlainTxOut(
447+
final psbtInDummy = payjoin.PsbtInput(
448+
witnessUtxo: payjoin.TxOut(
449449
valueSat: 1,
450450
scriptPubkey: Uint8List.fromList([0x6a]),
451451
),
@@ -461,18 +461,18 @@ void main() {
461461
throwsA(isA<payjoin.InputPairException>()),
462462
);
463463

464-
final txin = payjoin.PlainTxIn(
464+
final txin = payjoin.TxIn(
465465
// valid 32-byte txid so we exercise amount overflow instead of outpoint parsing
466-
previousOutput: payjoin.PlainOutPoint(txid: "00" * 32, vout: 0),
466+
previousOutput: payjoin.OutPoint(txid: "00" * 32, vout: 0),
467467
scriptSig: Uint8List(0),
468468
sequence: 0,
469469
witness: <Uint8List>[],
470470
);
471-
final txout = payjoin.PlainTxOut(
471+
final txout = payjoin.TxOut(
472472
valueSat: tooLargeAmount,
473473
scriptPubkey: Uint8List.fromList([0x6a]),
474474
);
475-
final psbtIn = payjoin.PlainPsbtInput(
475+
final psbtIn = payjoin.PsbtInput(
476476
witnessUtxo: txout,
477477
redeemScript: null,
478478
witnessScript: null,
@@ -507,7 +507,7 @@ void main() {
507507
() => payjoin.SenderBuilder(
508508
psbt: psbt,
509509
uri: pjUri,
510-
).buildRecommended(minFeeRate: overflowFeeRate),
510+
).buildRecommended(minFeeRateSatPerKwu: overflowFeeRate),
511511
throwsA(isA<payjoin.SenderInputException>()),
512512
);
513513

@@ -555,10 +555,10 @@ void main() {
555555
// Create a funded PSBT (not broadcasted) to address with amount given in the pj_uri
556556
var pj_uri = session.pjUri();
557557
var psbt = build_sweep_psbt(sender, pj_uri);
558-
payjoin.WithReplyKey req_ctx = payjoin.SenderBuilder(
559-
psbt: psbt,
560-
uri: pj_uri,
561-
).buildRecommended(minFeeRate: 1000).save(persister: sender_persister);
558+
payjoin.WithReplyKey req_ctx =
559+
payjoin.SenderBuilder(psbt: psbt, uri: pj_uri)
560+
.buildRecommended(minFeeRateSatPerKwu: 1000)
561+
.save(persister: sender_persister);
562562
payjoin.RequestOhttpContext request = req_ctx.createV2PostRequest(
563563
ohttpRelay: ohttp_relay,
564564
);

payjoin-ffi/dart/test/test_payjoin_unit_test.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ void main() {
189189

190190
var sender_persister = InMemorySenderPersister("1");
191191
var psbt = payjoin.originalPsbt();
192-
payjoin.SenderBuilder(
193-
psbt: psbt,
194-
uri: uri,
195-
).buildRecommended(minFeeRate: 1000).save(persister: sender_persister);
192+
payjoin.SenderBuilder(psbt: psbt, uri: uri)
193+
.buildRecommended(minFeeRateSatPerKwu: 1000)
194+
.save(persister: sender_persister);
196195
final senderResult = payjoin.replaySenderEventLog(
197196
persister: sender_persister,
198197
);
@@ -274,10 +273,9 @@ void main() {
274273

275274
var sender_persister = InMemorySenderPersister("1");
276275
var psbt = payjoin.originalPsbt();
277-
var withReplyKey = payjoin.SenderBuilder(
278-
psbt: psbt,
279-
uri: uri,
280-
).buildRecommended(minFeeRate: 1000).save(persister: sender_persister);
276+
var withReplyKey = payjoin.SenderBuilder(psbt: psbt, uri: uri)
277+
.buildRecommended(minFeeRateSatPerKwu: 1000)
278+
.save(persister: sender_persister);
281279
var cancelTransition = withReplyKey.cancel();
282280
var fallbackTx = cancelTransition.save(persister: sender_persister);
283281
expect(fallbackTx, isNotNull);
@@ -308,7 +306,7 @@ void main() {
308306
var sender_persister = InMemorySenderPersisterAsync("1");
309307
var psbt = payjoin.originalPsbt();
310308
var withReplyKey = await payjoin.SenderBuilder(psbt: psbt, uri: uri)
311-
.buildRecommended(minFeeRate: 1000)
309+
.buildRecommended(minFeeRateSatPerKwu: 1000)
312310
.saveAsync(persister: sender_persister);
313311
var cancelTransition = withReplyKey.cancel();
314312
var fallbackTx = await cancelTransition.saveAsync(
@@ -369,7 +367,7 @@ void main() {
369367
var sender_persister = InMemorySenderPersisterAsync("1");
370368
var psbt = payjoin.originalPsbt();
371369
await payjoin.SenderBuilder(psbt: psbt, uri: uri)
372-
.buildRecommended(minFeeRate: 1000)
370+
.buildRecommended(minFeeRateSatPerKwu: 1000)
373371
.saveAsync(persister: sender_persister);
374372
final senderResult = await payjoin.replaySenderEventLogAsync(
375373
persister: sender_persister,

payjoin-ffi/javascript/test/integration.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,20 @@ function getInputs(rpcConnection: testUtils.RpcClient): payjoin.InputPair[] {
214214
const utxos: Utxo[] = JSON.parse(rpcConnection.call("listunspent", []));
215215
const inputs: payjoin.InputPair[] = [];
216216
for (const utxo of utxos) {
217-
const txin = payjoin.PlainTxIn.create({
218-
previousOutput: payjoin.PlainOutPoint.create({
217+
const txin = payjoin.TxIn.create({
218+
previousOutput: payjoin.OutPoint.create({
219219
txid: utxo.txid,
220220
vout: utxo.vout,
221221
}),
222222
scriptSig: new Uint8Array([]),
223223
sequence: 0,
224224
witness: [],
225225
});
226-
const txOut = payjoin.PlainTxOut.create({
226+
const txOut = payjoin.TxOut.create({
227227
valueSat: BigInt(Math.round(utxo.amount * 100_000_000)),
228228
scriptPubkey: Buffer.from(utxo.scriptPubKey, "hex"),
229229
});
230-
const psbtIn = payjoin.PlainPsbtInput.create({
230+
const psbtIn = payjoin.PsbtInput.create({
231231
witnessUtxo: txOut,
232232
redeemScript: undefined,
233233
witnessScript: undefined,
@@ -454,20 +454,20 @@ function testFfiValidation(): void {
454454
const tooLargeAmount = 21000000n * 100000000n + 1n;
455455

456456
// Invalid outpoint (txid too long) should fail before amount checks.
457-
const invalidOutpointTxIn = payjoin.PlainTxIn.create({
458-
previousOutput: payjoin.PlainOutPoint.create({
457+
const invalidOutpointTxIn = payjoin.TxIn.create({
458+
previousOutput: payjoin.OutPoint.create({
459459
txid: "00".repeat(64), // 64 bytes -> invalid
460460
vout: 0,
461461
}),
462462
scriptSig: new Uint8Array([]).buffer,
463463
sequence: 0,
464464
witness: [],
465465
});
466-
const txout = payjoin.PlainTxOut.create({
466+
const txout = payjoin.TxOut.create({
467467
valueSat: tooLargeAmount,
468468
scriptPubkey: new Uint8Array([0x6a]).buffer,
469469
});
470-
const psbtIn = payjoin.PlainPsbtInput.create({
470+
const psbtIn = payjoin.PsbtInput.create({
471471
witnessUtxo: txout,
472472
redeemScript: undefined,
473473
witnessScript: undefined,
@@ -477,8 +477,8 @@ function testFfiValidation(): void {
477477
}, /InvalidOutPoint/);
478478

479479
// Valid outpoint hits amount overflow validation.
480-
const amountOverflowTxIn = payjoin.PlainTxIn.create({
481-
previousOutput: payjoin.PlainOutPoint.create({
480+
const amountOverflowTxIn = payjoin.TxIn.create({
481+
previousOutput: payjoin.OutPoint.create({
482482
txid: "00".repeat(32), // valid 32-byte txid
483483
vout: 0,
484484
}),
@@ -496,11 +496,11 @@ function testFfiValidation(): void {
496496

497497
// Oversized script_pubkey should fail.
498498
const hugeScript = new Uint8Array(10_001).fill(0x51).buffer;
499-
const oversizedTxOut = payjoin.PlainTxOut.create({
499+
const oversizedTxOut = payjoin.TxOut.create({
500500
valueSat: 1n,
501501
scriptPubkey: hugeScript,
502502
});
503-
const oversizedPsbtIn = payjoin.PlainPsbtInput.create({
503+
const oversizedPsbtIn = payjoin.PsbtInput.create({
504504
witnessUtxo: oversizedTxOut,
505505
redeemScript: undefined,
506506
witnessScript: undefined,
@@ -514,11 +514,11 @@ function testFfiValidation(): void {
514514
}
515515

516516
// Weight must be positive and <= block weight.
517-
const smallTxOut = payjoin.PlainTxOut.create({
517+
const smallTxOut = payjoin.TxOut.create({
518518
valueSat: 1n,
519519
scriptPubkey: new Uint8Array([0x6a]).buffer,
520520
});
521-
const smallPsbtIn = payjoin.PlainPsbtInput.create({
521+
const smallPsbtIn = payjoin.PsbtInput.create({
522522
witnessUtxo: smallTxOut,
523523
redeemScript: undefined,
524524
witnessScript: undefined,
@@ -527,7 +527,7 @@ function testFfiValidation(): void {
527527
new payjoin.InputPair(
528528
amountOverflowTxIn,
529529
smallPsbtIn,
530-
payjoin.PlainWeight.create({ weightUnits: 0n }),
530+
payjoin.Weight.create({ weightUnits: 0n }),
531531
);
532532
assert.fail("Expected WeightOutOfRange error");
533533
} catch (e) {

payjoin-ffi/javascript/test/unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,16 @@ describe("Validation", () => {
486486

487487
test("input pair rejects invalid outpoint", () => {
488488
assert.throws(() => {
489-
const txin = payjoin.PlainTxIn.create({
490-
previousOutput: payjoin.PlainOutPoint.create({
489+
const txin = payjoin.TxIn.create({
490+
previousOutput: payjoin.OutPoint.create({
491491
txid: "deadbeef",
492492
vout: 0,
493493
}),
494494
scriptSig: new Uint8Array([]),
495495
sequence: 0,
496496
witness: [],
497497
});
498-
const psbtIn = payjoin.PlainPsbtInput.create({
498+
const psbtIn = payjoin.PsbtInput.create({
499499
witnessUtxo: undefined,
500500
redeemScript: undefined,
501501
witnessScript: undefined,

0 commit comments

Comments
 (0)