Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 314fb00

Browse files
authored
Merge d792690 into de8afec
2 parents de8afec + d792690 commit 314fb00

14 files changed

Lines changed: 267 additions & 491 deletions

package-lock.json

Lines changed: 131 additions & 272 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bitcoin/lib/Value.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export class Value implements ICloneable<Value> {
3333
return new Value(BigInt(num) * BigInt(1e9));
3434
}
3535

36+
/**
37+
* Creates a value instance from value in microsatoshis, 1/1e6 of a
38+
* satoshi.
39+
* eg: 123 microsatoshis equates to 0.000123 satoshis
40+
* eg: 123 microsatoshis equates to 0.00000000000123 bitcoin
41+
* @param num
42+
*/
43+
public static fromMicroSats(num: bigint | number) {
44+
return new Value(BigInt(num) * BigInt(1e6));
45+
}
46+
3647
/**
3748
* Creates a value instance from value in picosatoshis, 1/1e12 of a
3849
* satoshi.
@@ -60,6 +71,13 @@ export class Value implements ICloneable<Value> {
6071
return this._picoSats;
6172
}
6273

74+
/**
75+
* Gets the value in millionth of satoshis (1/1e6 satoshis)
76+
*/
77+
public get microsats(): bigint {
78+
return this._picoSats / BigInt(1e6);
79+
}
80+
6381
/**
6482
* Gets the value in millisatoshis (1/1000 satoshis)
6583
*/

packages/graph/__tests__/graph-manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable: no-unused-expression
2-
import { BitField } from "@node-lightning/core";
2+
import { BitField, Value } from "@node-lightning/core";
33
import { ShortChannelId } from "@node-lightning/core";
44
import { OutPoint } from "@node-lightning/core";
55
import { AddressIPv4 } from "@node-lightning/wire";

packages/graph/lib/deserialize/channel-settings-from-message.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export function channelSettingsFromMessage(msg: ChannelUpdateMessage): ChannelSe
1010
instance.direction = msg.direction;
1111
instance.timestamp = msg.timestamp;
1212
instance.cltvExpiryDelta = msg.cltvExpiryDelta;
13-
instance.htlcMinimumMsat = msg.htlcMinimumMsat;
14-
instance.htlcMaximumMsat = msg.htlcMaximumMsat;
15-
instance.feeBaseMsat = msg.feeBaseMsat;
16-
instance.feeProportionalMillionths = msg.feeProportionalMillionths;
13+
instance.htlcMinimumMsat = null;
14+
instance.htlcMaximumMsat = null;
15+
instance.feeBaseMsat = null;
16+
instance.feeProportionalMillionths = null;
1717
instance.disabled = msg.disabled;
1818
return instance;
1919
}

packages/invoice/package-lock.json

Lines changed: 0 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wire/__tests__/gossip/GossipFilter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ describe("GossipFilter", () => {
199199
const msg = await gossipStore.findChannelUpdate(new ShortChannelId(1288457, 3, 0), 1);
200200
expect(msg.timestamp).to.equal(1525140553);
201201
expect(msg.cltvExpiryDelta).to.equal(144);
202-
expect(msg.htlcMinimumMsat).to.equal(BigInt(1000));
202+
expect(msg.htlcMinimumMsat.msats).to.equal(BigInt(1000));
203203
expect(msg.htlcMaximumMsat).to.be.undefined;
204-
expect(msg.feeBaseMsat).to.equal(1000);
205-
expect(msg.feeProportionalMillionths).to.equal(1);
204+
expect(Number(msg.feeBaseMsat.msats)).to.equal(1000);
205+
expect(Number(msg.feeProportionalMillionths.microsats)).to.equal(1);
206206
expect(msg.disabled).to.be.false;
207207
});
208208

packages/wire/__tests__/messages/AcceptChannelMessage.spec.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as crypto from "@node-lightning/crypto";
22
import { expect } from "chai";
33
import { AcceptChannelMessage } from "../../lib/messages/AcceptChannelMessage";
4+
import { Value } from "@node-lightning/core";
45

56
describe("AcceptChannelMessage", () => {
67
// abb00e1f13665a56d7b39917a3afa1a9753191e97541334705e39019c0e3d9b4
@@ -41,10 +42,10 @@ describe("AcceptChannelMessage", () => {
4142
"0000000000000000000000000000000000000000000000000000000000000000",
4243
"hex",
4344
);
44-
instance.dustLimitSatoshis = BigInt(330);
45-
instance.maxHtlcValueInFlightMsat = BigInt(20000);
46-
instance.channelReserveSatoshis = BigInt(2000);
47-
instance.htlcMinimumMsat = BigInt(200);
45+
instance.dustLimitSatoshis = Value.fromSats(330);
46+
instance.maxHtlcValueInFlightMsat = Value.fromMilliSats(20000);
47+
instance.channelReserveSatoshis = Value.fromSats(2000);
48+
instance.htlcMinimumMsat = Value.fromMilliSats(200);
4849
instance.minimumDepth = 6;
4950
instance.toSelfDelay = 144;
5051
instance.maxAcceptedHtlcs = 30;
@@ -80,10 +81,10 @@ describe("AcceptChannelMessage", () => {
8081
"0000000000000000000000000000000000000000000000000000000000000000",
8182
"hex",
8283
);
83-
instance.dustLimitSatoshis = BigInt(330);
84-
instance.maxHtlcValueInFlightMsat = BigInt(20000);
85-
instance.channelReserveSatoshis = BigInt(2000);
86-
instance.htlcMinimumMsat = BigInt(200);
84+
instance.dustLimitSatoshis = Value.fromSats(330);
85+
instance.maxHtlcValueInFlightMsat = Value.fromMilliSats(20000);
86+
instance.channelReserveSatoshis = Value.fromSats(2000);
87+
instance.htlcMinimumMsat = Value.fromMilliSats(200);
8788
instance.minimumDepth = 6;
8889
instance.toSelfDelay = 144;
8990
instance.maxAcceptedHtlcs = 30;
@@ -151,10 +152,10 @@ describe("AcceptChannelMessage", () => {
151152
"hex",
152153
),
153154
);
154-
expect(instance.dustLimitSatoshis).to.equal(BigInt(330));
155-
expect(instance.maxHtlcValueInFlightMsat).to.equal(BigInt(20000));
156-
expect(instance.channelReserveSatoshis).to.equal(BigInt(2000));
157-
expect(instance.htlcMinimumMsat).to.equal(BigInt(200));
155+
expect(instance.dustLimitSatoshis.sats).to.equal(BigInt(330));
156+
expect(instance.maxHtlcValueInFlightMsat.msats).to.equal(BigInt(20000));
157+
expect(instance.channelReserveSatoshis.sats).to.equal(BigInt(2000));
158+
expect(instance.htlcMinimumMsat.msats).to.equal(BigInt(200));
158159
expect(instance.minimumDepth).to.equal(6);
159160
expect(instance.toSelfDelay).to.equal(144);
160161
expect(instance.maxAcceptedHtlcs).to.equal(30);

packages/wire/__tests__/messages/ChannelUpdateMessage.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tslint:disable: no-unused-expression
2-
import { BitField } from "@node-lightning/core";
3-
import { ShortChannelId } from "@node-lightning/core";
2+
import { BitField, ShortChannelId, Value } from "@node-lightning/core";
43
import { expect } from "chai";
54
import { ChannelUpdateMessage } from "../../lib/messages/ChannelUpdateMessage";
65

@@ -29,10 +28,10 @@ describe("ChannelUpdateMessage", () => {
2928
expect(result.messageFlags.value).to.equal(BigInt(1));
3029
expect(result.channelFlags.value).to.equal(BigInt(0));
3130
expect(result.cltvExpiryDelta).to.equal(144);
32-
expect(Number(result.htlcMinimumMsat)).to.equal(1000);
33-
expect(Number(result.htlcMaximumMsat)).to.equal(100000000);
34-
expect(result.feeBaseMsat).to.equal(1000);
35-
expect(result.feeProportionalMillionths).to.equal(1);
31+
expect(Number(result.htlcMinimumMsat.msats)).to.equal(1000);
32+
expect(Number(result.htlcMaximumMsat.msats)).to.equal(100000000);
33+
expect(Number(result.feeBaseMsat.msats)).to.equal(1000);
34+
expect(Number(result.feeProportionalMillionths.microsats)).to.equal(1);
3635
expect(result.direction).to.equal(0);
3736
expect(result.disabled).to.be.false;
3837
});
@@ -48,10 +47,10 @@ describe("ChannelUpdateMessage", () => {
4847
instance.messageFlags = new BitField(BigInt(1));
4948
instance.channelFlags = new BitField(BigInt(0));
5049
instance.cltvExpiryDelta = 144;
51-
instance.htlcMinimumMsat = BigInt(1000);
52-
instance.htlcMaximumMsat = BigInt(100000000);
53-
instance.feeBaseMsat = 1000;
54-
instance.feeProportionalMillionths = 1;
50+
instance.htlcMinimumMsat = Value.fromMilliSats(1000);
51+
instance.htlcMaximumMsat = Value.fromMilliSats(100000000);
52+
instance.feeBaseMsat = Value.fromMilliSats(1000);
53+
instance.feeProportionalMillionths = Value.fromMicroSats(1);
5554

5655
const result = instance.serialize();
5756
expect(result.toString("hex")).to.deep.equal(

packages/wire/__tests__/messages/ClosingSignedMessage.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChannelId } from "@node-lightning/core";
1+
import { ChannelId, Value } from "@node-lightning/core";
22
import { expect } from "chai";
33
import { ClosingSignedMessage } from "../../lib/messages/ClosingSignedMessage";
44

@@ -14,7 +14,7 @@ describe("ClosingSignedMessage", () => {
1414
const result = ClosingSignedMessage.deserialize(input);
1515
expect(result.type).to.equal(39);
1616
expect(result.channelId.toString()).to.equal("0000000000000000000000000000000000000000000000000000000000000000"); // prettier-ignore
17-
expect(result.feeSatoshis).to.equal(BigInt(200000));
17+
expect(result.feeSatoshis.sats).to.equal(BigInt(200000));
1818
expect(result.signature.toString("hex")).to.equal("22222222222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333333333333333"); // prettier-ignore
1919
});
2020
});
@@ -23,7 +23,7 @@ describe("ClosingSignedMessage", () => {
2323
it("should serialize a message", () => {
2424
const instance = new ClosingSignedMessage();
2525
instance.channelId = new ChannelId(Buffer.from("0000000000000000000000000000000000000000000000000000000000000000", "hex")); // prettier-ignore
26-
instance.feeSatoshis = BigInt(200000);
26+
instance.feeSatoshis = Value.fromSats(200000);
2727
instance.signature = Buffer.from("22222222222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333333333333333333333333", "hex"); // prettier-ignore
2828

2929
const result = instance.serialize();

packages/wire/__tests__/messages/OpenChannelMessage.spec.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as crypto from "@node-lightning/crypto";
22
import { expect } from "chai";
33
import { OpenChannelMessage } from "../../lib/messages/OpenChannelMessage";
4+
import { Value, Script } from "@node-lightning/core";
45

56
describe("OpenChannelMessage", () => {
67
// abb00e1f13665a56d7b39917a3afa1a9753191e97541334705e39019c0e3d9b4
@@ -45,13 +46,13 @@ describe("OpenChannelMessage", () => {
4546
"0000000000000000000000000000000000000000000000000000000000000000",
4647
"hex",
4748
);
48-
instance.fundingSatoshis = BigInt(200000);
49-
instance.pushMsat = BigInt(2000);
50-
instance.dustLimitSatoshis = BigInt(330);
51-
instance.maxHtlcValueInFlightMsat = BigInt(20000);
52-
instance.channelReserveSatoshis = BigInt(2000);
53-
instance.htlcMinimumMsat = BigInt(200);
54-
instance.feeRatePerKw = 1000;
49+
instance.fundingSatoshis = Value.fromSats(200000);
50+
instance.pushMsat = Value.fromMilliSats(2000);
51+
instance.dustLimitSatoshis = Value.fromSats(330);
52+
instance.maxHtlcValueInFlightMsat = Value.fromMilliSats(20000);
53+
instance.channelReserveSatoshis = Value.fromSats(2000);
54+
instance.htlcMinimumMsat = Value.fromMilliSats(200);
55+
instance.feeRatePerKw = Value.fromSats(1000);
5556
instance.toSelfDelay = 144;
5657
instance.maxAcceptedHtlcs = 30;
5758
instance.fundingPubKey = fundingPubKey;
@@ -95,13 +96,13 @@ describe("OpenChannelMessage", () => {
9596
"0000000000000000000000000000000000000000000000000000000000000000",
9697
"hex",
9798
);
98-
instance.fundingSatoshis = BigInt(200000);
99-
instance.pushMsat = BigInt(2000);
100-
instance.dustLimitSatoshis = BigInt(330);
101-
instance.maxHtlcValueInFlightMsat = BigInt(20000);
102-
instance.channelReserveSatoshis = BigInt(2000);
103-
instance.htlcMinimumMsat = BigInt(200);
104-
instance.feeRatePerKw = 1000;
99+
instance.fundingSatoshis = Value.fromSats(200000);
100+
instance.pushMsat = Value.fromMilliSats(2000);
101+
instance.dustLimitSatoshis = Value.fromSats(330);
102+
instance.maxHtlcValueInFlightMsat = Value.fromMilliSats(20000);
103+
instance.channelReserveSatoshis = Value.fromSats(2000);
104+
instance.htlcMinimumMsat = Value.fromMilliSats(200);
105+
instance.feeRatePerKw = Value.fromSats(1000);
105106
instance.toSelfDelay = 144;
106107
instance.maxAcceptedHtlcs = 30;
107108
instance.fundingPubKey = fundingPubKey;
@@ -145,13 +146,13 @@ describe("OpenChannelMessage", () => {
145146
"0000000000000000000000000000000000000000000000000000000000000000",
146147
"hex",
147148
);
148-
instance.fundingSatoshis = BigInt(200000);
149-
instance.pushMsat = BigInt(2000);
150-
instance.dustLimitSatoshis = BigInt(330);
151-
instance.maxHtlcValueInFlightMsat = BigInt(20000);
152-
instance.channelReserveSatoshis = BigInt(2000);
153-
instance.htlcMinimumMsat = BigInt(200);
154-
instance.feeRatePerKw = 1000;
149+
instance.fundingSatoshis = Value.fromSats(200000);
150+
instance.pushMsat = Value.fromMilliSats(2000);
151+
instance.dustLimitSatoshis = Value.fromSats(330);
152+
instance.maxHtlcValueInFlightMsat = Value.fromMilliSats(20000);
153+
instance.channelReserveSatoshis = Value.fromSats(2000);
154+
instance.htlcMinimumMsat = Value.fromMilliSats(200);
155+
instance.feeRatePerKw = Value.fromSats(1000);
155156
instance.toSelfDelay = 144;
156157
instance.maxAcceptedHtlcs = 30;
157158
instance.fundingPubKey = fundingPubKey;
@@ -233,13 +234,13 @@ describe("OpenChannelMessage", () => {
233234
"hex",
234235
),
235236
);
236-
expect(instance.fundingSatoshis).to.equal(BigInt(200000));
237-
expect(instance.pushMsat).to.equal(BigInt(2000));
238-
expect(instance.dustLimitSatoshis).to.equal(BigInt(330));
239-
expect(instance.maxHtlcValueInFlightMsat).to.equal(BigInt(20000));
240-
expect(instance.channelReserveSatoshis).to.equal(BigInt(2000));
241-
expect(instance.htlcMinimumMsat).to.equal(BigInt(200));
242-
expect(instance.feeRatePerKw).to.equal(1000);
237+
expect(instance.fundingSatoshis.sats).to.equal(BigInt(200000));
238+
expect(instance.pushMsat.msats).to.equal(BigInt(2000));
239+
expect(instance.dustLimitSatoshis.sats).to.equal(BigInt(330));
240+
expect(instance.maxHtlcValueInFlightMsat.msats).to.equal(BigInt(20000));
241+
expect(instance.channelReserveSatoshis.sats).to.equal(BigInt(2000));
242+
expect(instance.htlcMinimumMsat.msats).to.equal(BigInt(200));
243+
expect(Number(instance.feeRatePerKw.sats)).to.equal(1000);
243244
expect(instance.toSelfDelay).to.equal(144);
244245
expect(instance.maxAcceptedHtlcs).to.equal(30);
245246
expect(instance.fundingPubKey).to.deep.equal(fundingPubKey);

0 commit comments

Comments
 (0)