@lightsparkdev/lightspark-sdk 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.fossa.yml +6 -0
- package/.prettierrc +1 -0
- package/.turbo/turbo-build.log +19 -0
- package/.turbo/turbo-lint.log +3 -0
- package/CHANGELOG.md +49 -0
- package/LICENSE +201 -0
- package/README.md +137 -0
- package/dist/Withdrawal-17e1c8af.d.ts +1672 -0
- package/dist/Withdrawal-27a4d10d.d.ts +1672 -0
- package/dist/chunk-3VRI7CHE.js +5508 -0
- package/dist/chunk-AGEUDR2V.js +4498 -0
- package/dist/chunk-N27QHRE4.js +5508 -0
- package/dist/client-3bba3f64.d.ts +1302 -0
- package/dist/index.cjs +6633 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1177 -0
- package/dist/objects/index.cjs +5347 -0
- package/dist/objects/index.d.ts +3 -0
- package/dist/objects/index.js +88 -0
- package/examples/node-scripts/authHelpers.ts +20 -0
- package/examples/node-scripts/createInvoice.ts +64 -0
- package/examples/node-scripts/example.ts +288 -0
- package/examples/node-scripts/getAccountDashboard.ts +24 -0
- package/examples/node-scripts/getNodeChannels.ts +34 -0
- package/examples/node-scripts/internalAuthHelpers.ts +26 -0
- package/examples/node-scripts/internal_example.ts +296 -0
- package/examples/node-scripts/package-lock.json +887 -0
- package/examples/node-scripts/package.json +22 -0
- package/examples/node-scripts/prettyPrintJsonForDocs.ts +62 -0
- package/examples/node-scripts/tsconfig.json +27 -0
- package/examples/oauth-example/README.md +19 -0
- package/examples/oauth-example/package-lock.json +16071 -0
- package/examples/oauth-example/package.json +50 -0
- package/examples/oauth-example/public/favicon.ico +0 -0
- package/examples/oauth-example/public/index.html +43 -0
- package/examples/oauth-example/public/logo192.png +0 -0
- package/examples/oauth-example/public/logo512.png +0 -0
- package/examples/oauth-example/public/manifest.json +25 -0
- package/examples/oauth-example/public/robots.txt +3 -0
- package/examples/oauth-example/src/App.css +7 -0
- package/examples/oauth-example/src/App.test.tsx +12 -0
- package/examples/oauth-example/src/App.tsx +16 -0
- package/examples/oauth-example/src/auth/AuthContext.ts +8 -0
- package/examples/oauth-example/src/auth/AuthProvider.tsx +44 -0
- package/examples/oauth-example/src/auth/RequireAuth.tsx +19 -0
- package/examples/oauth-example/src/auth/oauthProvider.ts +35 -0
- package/examples/oauth-example/src/components/Button.tsx +39 -0
- package/examples/oauth-example/src/components/CurrencyAmount.tsx +117 -0
- package/examples/oauth-example/src/components/Dashboard.tsx +158 -0
- package/examples/oauth-example/src/components/Table.tsx +22 -0
- package/examples/oauth-example/src/hooks/useAccountInfo.tsx +31 -0
- package/examples/oauth-example/src/icons/BitcoinB.tsx +20 -0
- package/examples/oauth-example/src/icons/Icon.tsx +121 -0
- package/examples/oauth-example/src/icons/Satoshi.tsx +28 -0
- package/examples/oauth-example/src/index.css +13 -0
- package/examples/oauth-example/src/index.tsx +23 -0
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientContext.ts +10 -0
- package/examples/oauth-example/src/lightsparkclient/LightsparkClientProvider.tsx +53 -0
- package/examples/oauth-example/src/logo.svg +1 -0
- package/examples/oauth-example/src/pages/DashboardPage.tsx +71 -0
- package/examples/oauth-example/src/pages/LoginPage.tsx +63 -0
- package/examples/oauth-example/src/react-app-env.d.ts +1 -0
- package/examples/oauth-example/src/reportWebVitals.ts +15 -0
- package/examples/oauth-example/src/routes/index.tsx +15 -0
- package/examples/oauth-example/src/setupTests.ts +5 -0
- package/examples/oauth-example/src/utils/currency.ts +483 -0
- package/examples/oauth-example/tsconfig.json +20 -0
- package/examples/streaming-wallet-extension/.fossa.yml +6 -0
- package/examples/streaming-wallet-extension/README.md +17 -0
- package/examples/streaming-wallet-extension/craco.config.js +58 -0
- package/examples/streaming-wallet-extension/package-lock.json +18260 -0
- package/examples/streaming-wallet-extension/package.json +77 -0
- package/examples/streaming-wallet-extension/public/index.html +24 -0
- package/examples/streaming-wallet-extension/public/lightspark_full.png +0 -0
- package/examples/streaming-wallet-extension/public/lightspark_icon_circle.png +0 -0
- package/examples/streaming-wallet-extension/public/manifest.json +43 -0
- package/examples/streaming-wallet-extension/public/robots.txt +3 -0
- package/examples/streaming-wallet-extension/src/App.css +53 -0
- package/examples/streaming-wallet-extension/src/App.tsx +425 -0
- package/examples/streaming-wallet-extension/src/auth/AccountStorage.ts +28 -0
- package/examples/streaming-wallet-extension/src/auth/DemoAccountProvider.ts +99 -0
- package/examples/streaming-wallet-extension/src/auth/StreamingDemoCredentials.ts +10 -0
- package/examples/streaming-wallet-extension/src/background/PaymentStrategy.ts +36 -0
- package/examples/streaming-wallet-extension/src/background/PlaybackRange.ts +31 -0
- package/examples/streaming-wallet-extension/src/background/StreamingInvoiceHolder.ts +33 -0
- package/examples/streaming-wallet-extension/src/background/TransactionObserver.ts +66 -0
- package/examples/streaming-wallet-extension/src/background/VideoPlaybackRanges.ts +38 -0
- package/examples/streaming-wallet-extension/src/background/VideoProgressCache.ts +87 -0
- package/examples/streaming-wallet-extension/src/background/background.ts +145 -0
- package/examples/streaming-wallet-extension/src/background/messageHandling.ts +185 -0
- package/examples/streaming-wallet-extension/src/common/datetimes.ts +28 -0
- package/examples/streaming-wallet-extension/src/common/settings.ts +12 -0
- package/examples/streaming-wallet-extension/src/common/storage.ts +8 -0
- package/examples/streaming-wallet-extension/src/common/streamingTabs.ts +27 -0
- package/examples/streaming-wallet-extension/src/common/types.tsx +23 -0
- package/examples/streaming-wallet-extension/src/components/CirclePlusIcon.tsx +19 -0
- package/examples/streaming-wallet-extension/src/components/CurrencyAmount.tsx +110 -0
- package/examples/streaming-wallet-extension/src/components/CurrencyAmountRaw.tsx +195 -0
- package/examples/streaming-wallet-extension/src/components/LeftArrow.tsx +21 -0
- package/examples/streaming-wallet-extension/src/components/Loading.tsx +151 -0
- package/examples/streaming-wallet-extension/src/components/StreamingTransactionChip.tsx +95 -0
- package/examples/streaming-wallet-extension/src/components/TransactionRow.tsx +93 -0
- package/examples/streaming-wallet-extension/src/contentscript/content.ts +123 -0
- package/examples/streaming-wallet-extension/src/contentscript/lightsparkDemoDom.tsx +113 -0
- package/examples/streaming-wallet-extension/src/contentscript/videoElementParsers.ts +92 -0
- package/examples/streaming-wallet-extension/src/index.css +16 -0
- package/examples/streaming-wallet-extension/src/index.tsx +11 -0
- package/examples/streaming-wallet-extension/src/lightsparkClientProvider.tsx +26 -0
- package/examples/streaming-wallet-extension/src/react-app-env.d.ts +1 -0
- package/examples/streaming-wallet-extension/src/types/Messages.ts +17 -0
- package/examples/streaming-wallet-extension/tsconfig.json +20 -0
- package/package.json +87 -0
- package/src/auth/AccountTokenAuthProvider.ts +37 -0
- package/src/auth/index.ts +3 -0
- package/src/client.ts +759 -0
- package/src/graphql/BitcoinFeeEstimate.ts +13 -0
- package/src/graphql/CreateApiToken.ts +22 -0
- package/src/graphql/CreateInvoice.ts +18 -0
- package/src/graphql/CreateNodeWalletAddress.ts +13 -0
- package/src/graphql/CurrentAccount.ts +13 -0
- package/src/graphql/DecodeInvoice.ts +16 -0
- package/src/graphql/DeleteApiToken.ts +13 -0
- package/src/graphql/FundNode.ts +18 -0
- package/src/graphql/LightningFeeEstimateForInvoice.ts +21 -0
- package/src/graphql/LightningFeeEstimateForNode.ts +21 -0
- package/src/graphql/MultiNodeDashboard.ts +118 -0
- package/src/graphql/PayInvoice.ts +29 -0
- package/src/graphql/RecoverNodeSigningKey.ts +15 -0
- package/src/graphql/RequestWithdrawal.ts +25 -0
- package/src/graphql/SendPayment.ts +29 -0
- package/src/graphql/SingleNodeDashboard.ts +116 -0
- package/src/graphql/TransactionSubscription.ts +16 -0
- package/src/graphql/TransactionsForNode.ts +42 -0
- package/src/index.ts +5 -0
- package/src/objects/Account.ts +1222 -0
- package/src/objects/AccountToApiTokensConnection.ts +50 -0
- package/src/objects/AccountToChannelsConnection.ts +35 -0
- package/src/objects/AccountToNodesConnection.ts +62 -0
- package/src/objects/AccountToPaymentRequestsConnection.ts +50 -0
- package/src/objects/AccountToTransactionsConnection.ts +112 -0
- package/src/objects/ApiToken.ts +80 -0
- package/src/objects/BitcoinNetwork.ts +19 -0
- package/src/objects/BlockchainBalance.ts +102 -0
- package/src/objects/Channel.ts +283 -0
- package/src/objects/ChannelClosingTransaction.ts +150 -0
- package/src/objects/ChannelFees.ts +34 -0
- package/src/objects/ChannelOpeningTransaction.ts +150 -0
- package/src/objects/ChannelStatus.ts +25 -0
- package/src/objects/ChannelToTransactionsConnection.ts +86 -0
- package/src/objects/CreateApiTokenInput.ts +22 -0
- package/src/objects/CreateApiTokenOutput.ts +41 -0
- package/src/objects/CreateInvoiceInput.ts +27 -0
- package/src/objects/CreateInvoiceOutput.ts +21 -0
- package/src/objects/CreateNodeWalletAddressInput.ts +15 -0
- package/src/objects/CreateNodeWalletAddressOutput.ts +27 -0
- package/src/objects/CurrencyAmount.ts +55 -0
- package/src/objects/CurrencyUnit.ts +25 -0
- package/src/objects/DeleteApiTokenInput.ts +13 -0
- package/src/objects/DeleteApiTokenOutput.ts +23 -0
- package/src/objects/Deposit.ts +144 -0
- package/src/objects/Entity.ts +868 -0
- package/src/objects/FeeEstimate.ts +39 -0
- package/src/objects/FundNodeInput.ts +16 -0
- package/src/objects/FundNodeOutput.ts +28 -0
- package/src/objects/GraphNode.ts +110 -0
- package/src/objects/Hop.ts +108 -0
- package/src/objects/HtlcAttemptFailureCode.ts +65 -0
- package/src/objects/IncomingPayment.ts +141 -0
- package/src/objects/IncomingPaymentAttempt.ts +96 -0
- package/src/objects/IncomingPaymentAttemptStatus.ts +20 -0
- package/src/objects/IncomingPaymentToAttemptsConnection.ts +39 -0
- package/src/objects/Invoice.ts +226 -0
- package/src/objects/InvoiceData.ts +185 -0
- package/src/objects/InvoiceType.ts +15 -0
- package/src/objects/LightningFeeEstimateForInvoiceInput.ts +28 -0
- package/src/objects/LightningFeeEstimateForNodeInput.ts +25 -0
- package/src/objects/LightningFeeEstimateOutput.ts +33 -0
- package/src/objects/LightningTransaction.ts +393 -0
- package/src/objects/LightsparkNode.ts +377 -0
- package/src/objects/LightsparkNodePurpose.ts +17 -0
- package/src/objects/LightsparkNodeStatus.ts +29 -0
- package/src/objects/LightsparkNodeToChannelsConnection.ts +50 -0
- package/src/objects/Node.ts +273 -0
- package/src/objects/NodeAddress.ts +29 -0
- package/src/objects/NodeAddressType.ts +18 -0
- package/src/objects/NodeToAddressesConnection.ts +39 -0
- package/src/objects/OnChainTransaction.ts +318 -0
- package/src/objects/OutgoingPayment.ts +319 -0
- package/src/objects/OutgoingPaymentAttempt.ts +164 -0
- package/src/objects/OutgoingPaymentAttemptStatus.ts +18 -0
- package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +37 -0
- package/src/objects/OutgoingPaymentToAttemptsConnection.ts +39 -0
- package/src/objects/PageInfo.ts +31 -0
- package/src/objects/PayInvoiceInput.ts +33 -0
- package/src/objects/PayInvoiceOutput.ts +22 -0
- package/src/objects/PaymentFailureReason.ts +29 -0
- package/src/objects/PaymentRequest.ts +231 -0
- package/src/objects/PaymentRequestData.ts +183 -0
- package/src/objects/PaymentRequestStatus.ts +15 -0
- package/src/objects/Permission.ts +39 -0
- package/src/objects/RequestWithdrawalInput.ts +35 -0
- package/src/objects/RequestWithdrawalOutput.ts +24 -0
- package/src/objects/RichText.ts +19 -0
- package/src/objects/RoutingTransaction.ts +150 -0
- package/src/objects/RoutingTransactionFailureReason.ts +17 -0
- package/src/objects/Secret.ts +23 -0
- package/src/objects/SendPaymentInput.ts +30 -0
- package/src/objects/SendPaymentOutput.ts +22 -0
- package/src/objects/Transaction.ts +609 -0
- package/src/objects/TransactionFailures.ts +23 -0
- package/src/objects/TransactionStatus.ts +23 -0
- package/src/objects/TransactionType.ts +31 -0
- package/src/objects/TransactionUpdate.ts +67 -0
- package/src/objects/WalletDashboard.ts +32 -0
- package/src/objects/WebhookEventType.ts +15 -0
- package/src/objects/Withdrawal.ts +144 -0
- package/src/objects/WithdrawalMode.ts +15 -0
- package/src/objects/WithdrawalRequest.ts +224 -0
- package/src/objects/WithdrawalRequestStatus.ts +17 -0
- package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +57 -0
- package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +57 -0
- package/src/objects/index.ts +108 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AccountTokenAuthProvider,
|
|
5
|
+
BitcoinNetwork,
|
|
6
|
+
CurrencyAmount,
|
|
7
|
+
getDepositQuery,
|
|
8
|
+
LightsparkClient,
|
|
9
|
+
LightsparkNode,
|
|
10
|
+
Node,
|
|
11
|
+
} from "@lightsparkdev/lightspark-sdk";
|
|
12
|
+
import day from "dayjs";
|
|
13
|
+
import utc from "dayjs/plugin/utc.js";
|
|
14
|
+
|
|
15
|
+
import { getCredentialsFromEnvOrThrow } from "./internalAuthHelpers.js";
|
|
16
|
+
|
|
17
|
+
day.extend(utc);
|
|
18
|
+
|
|
19
|
+
// Let's start by creating a client
|
|
20
|
+
const credentials = getCredentialsFromEnvOrThrow();
|
|
21
|
+
const client = new LightsparkClient(
|
|
22
|
+
new AccountTokenAuthProvider(
|
|
23
|
+
credentials.apiTokenClientId,
|
|
24
|
+
credentials.apiTokenClientSecret
|
|
25
|
+
),
|
|
26
|
+
"api.dev.dev.sparkinfra.net"
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Get some fee estimates for Bitcoin (L1) transactions
|
|
30
|
+
|
|
31
|
+
const feeEstimate = await client.getBitcoinFeeEstimate(BitcoinNetwork.REGTEST);
|
|
32
|
+
console.log(
|
|
33
|
+
`Fees for a fast transaction ${feeEstimate.feeFast.preferredCurrencyValueApprox} ${feeEstimate.feeFast.preferredCurrencyUnit}.`
|
|
34
|
+
);
|
|
35
|
+
console.log(
|
|
36
|
+
`Fees for a cheap transaction ${feeEstimate.feeMin.preferredCurrencyValueApprox} ${feeEstimate.feeMin.preferredCurrencyUnit}.\n`
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// List your account's lightning nodes
|
|
40
|
+
|
|
41
|
+
const account = await client.getCurrentAccount();
|
|
42
|
+
if (!account) {
|
|
43
|
+
throw new Error("Unable to fetch the account.");
|
|
44
|
+
}
|
|
45
|
+
console.log(`Your account name is ${account.name}.\n`);
|
|
46
|
+
|
|
47
|
+
// Test API token logic:
|
|
48
|
+
|
|
49
|
+
const apiTokenConnection = await account.getApiTokens(client);
|
|
50
|
+
console.log(`You have ${apiTokenConnection.count} API tokens.`);
|
|
51
|
+
|
|
52
|
+
const { apiToken, clientSecret } = await client.createApiToken(
|
|
53
|
+
"newTestToken",
|
|
54
|
+
false,
|
|
55
|
+
true
|
|
56
|
+
);
|
|
57
|
+
console.log(
|
|
58
|
+
`Created API token ${apiToken.name} with ID ${
|
|
59
|
+
apiToken.id
|
|
60
|
+
}. Permissions: ${JSON.stringify(apiToken.permissions)}\n`
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const apiTokenConnection2 = await account.getApiTokens(client);
|
|
64
|
+
console.log(`You now have ${apiTokenConnection2.count} API tokens.\n`);
|
|
65
|
+
|
|
66
|
+
client.deleteApiToken(apiToken.id);
|
|
67
|
+
|
|
68
|
+
const apiTokenConnection3 = await account.getApiTokens(client);
|
|
69
|
+
console.log(`You now have ${apiTokenConnection3.count} API tokens.\n`);
|
|
70
|
+
|
|
71
|
+
// Check our account's conductivity on REGTEST
|
|
72
|
+
|
|
73
|
+
console.log(
|
|
74
|
+
`Your account's conductivity on REGTEST is ${await account.getConductivity(
|
|
75
|
+
client,
|
|
76
|
+
[BitcoinNetwork.REGTEST]
|
|
77
|
+
)}/10.\n`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Check your account's local and remote balances for REGTEST
|
|
81
|
+
const localBalance = await account.getLocalBalance(client, [
|
|
82
|
+
BitcoinNetwork.REGTEST,
|
|
83
|
+
]);
|
|
84
|
+
const remoteBalance = await account.getRemoteBalance(client, [
|
|
85
|
+
BitcoinNetwork.REGTEST,
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
if (localBalance && remoteBalance) {
|
|
89
|
+
console.log(
|
|
90
|
+
`Your local balance is ${localBalance.preferredCurrencyValueApprox} ${localBalance.preferredCurrencyUnit},
|
|
91
|
+
your remote balance is ${remoteBalance.preferredCurrencyValueApprox} ${remoteBalance.preferredCurrencyUnit}.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const nodesConnection = await account.getNodes(client, 59, [
|
|
96
|
+
BitcoinNetwork.REGTEST,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
if (!nodesConnection) {
|
|
100
|
+
throw new Error("Unable to fetch the nodes.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log(`You have ${nodesConnection.count} nodes.`);
|
|
104
|
+
|
|
105
|
+
let node1Id: string | undefined;
|
|
106
|
+
let node2Id: string | undefined;
|
|
107
|
+
|
|
108
|
+
for (const node of nodesConnection.entities) {
|
|
109
|
+
if (node) {
|
|
110
|
+
console.log(` - ${node.displayName} (${node.status})`);
|
|
111
|
+
if (node.displayName == credentials.node1Name) node1Id = node.id;
|
|
112
|
+
else if (node.displayName == credentials.node2Name) node2Id = node.id;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.log("");
|
|
116
|
+
|
|
117
|
+
if (!node1Id || !node2Id) {
|
|
118
|
+
throw new Error("Unable to find the nodes.");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// List the transactions for our account
|
|
122
|
+
|
|
123
|
+
let transactionsConnection = await account.getTransactions(
|
|
124
|
+
client,
|
|
125
|
+
100,
|
|
126
|
+
undefined,
|
|
127
|
+
undefined,
|
|
128
|
+
undefined,
|
|
129
|
+
undefined,
|
|
130
|
+
BitcoinNetwork.REGTEST
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
console.log(
|
|
134
|
+
`There is a total of ${transactionsConnection.count} transaction(s) on this account:`
|
|
135
|
+
);
|
|
136
|
+
let depositTransactionId: string | undefined;
|
|
137
|
+
for (const transaction of transactionsConnection.entities) {
|
|
138
|
+
console.log(
|
|
139
|
+
` - ${transaction.typename} at ${transaction.createdAt}:
|
|
140
|
+
${transaction.amount.preferredCurrencyValueApprox} ${transaction.amount.preferredCurrencyUnit}
|
|
141
|
+
(${transaction.status})`
|
|
142
|
+
);
|
|
143
|
+
if (transaction.typename == "Deposit") {
|
|
144
|
+
depositTransactionId = transaction.id;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let fees;
|
|
148
|
+
if (
|
|
149
|
+
transaction.typename == "OutgoingPayment" ||
|
|
150
|
+
transaction.typename == "Withdrawal" ||
|
|
151
|
+
transaction.typename == "Deposit" ||
|
|
152
|
+
transaction.typename == "ChannelOpeningTransaction" ||
|
|
153
|
+
transaction.typename == "ChannelClosingTransaction"
|
|
154
|
+
) {
|
|
155
|
+
fees = (transaction as unknown as { fees: CurrencyAmount }).fees;
|
|
156
|
+
if (fees !== undefined)
|
|
157
|
+
console.log(
|
|
158
|
+
` Paid ${fees.preferredCurrencyValueApprox} ${fees.preferredCurrencyUnit} in fees.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
console.log("");
|
|
163
|
+
|
|
164
|
+
// Fetch transactions using pagination
|
|
165
|
+
const pageSize = 10;
|
|
166
|
+
let iterations = 0;
|
|
167
|
+
let hasNext = true;
|
|
168
|
+
let after: string | undefined = undefined;
|
|
169
|
+
while (hasNext && iterations < 30) {
|
|
170
|
+
iterations += 1;
|
|
171
|
+
transactionsConnection = await account.getTransactions(
|
|
172
|
+
client,
|
|
173
|
+
pageSize,
|
|
174
|
+
after,
|
|
175
|
+
undefined,
|
|
176
|
+
undefined,
|
|
177
|
+
undefined,
|
|
178
|
+
BitcoinNetwork.REGTEST
|
|
179
|
+
);
|
|
180
|
+
const num = transactionsConnection.entities.length;
|
|
181
|
+
console.log(
|
|
182
|
+
`We got ${num} transactions for the page (iteration #${iterations})`
|
|
183
|
+
);
|
|
184
|
+
if (transactionsConnection.pageInfo.hasNextPage) {
|
|
185
|
+
hasNext = true;
|
|
186
|
+
after = transactionsConnection.pageInfo.endCursor;
|
|
187
|
+
console.log(" And we have another page!");
|
|
188
|
+
} else {
|
|
189
|
+
hasNext = false;
|
|
190
|
+
console.log(" And we're done!");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
console.log("");
|
|
194
|
+
|
|
195
|
+
// Get the transactions that happened in the past day on REGTEST
|
|
196
|
+
|
|
197
|
+
transactionsConnection = await account.getTransactions(
|
|
198
|
+
client,
|
|
199
|
+
undefined,
|
|
200
|
+
undefined,
|
|
201
|
+
undefined,
|
|
202
|
+
day().utc().subtract(1, "day").format(),
|
|
203
|
+
undefined,
|
|
204
|
+
BitcoinNetwork.REGTEST
|
|
205
|
+
);
|
|
206
|
+
console.log(
|
|
207
|
+
`We had ${transactionsConnection.count} transactions in the past 24 hours.`
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Get details for a transaction
|
|
211
|
+
|
|
212
|
+
if (!depositTransactionId) {
|
|
213
|
+
throw new Error("Unable to find the deposit transaction.");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const deposit = await client.executeRawQuery(
|
|
217
|
+
getDepositQuery(depositTransactionId)
|
|
218
|
+
);
|
|
219
|
+
console.log("Details of deposit transaction");
|
|
220
|
+
console.log(deposit);
|
|
221
|
+
console.log("");
|
|
222
|
+
|
|
223
|
+
// Generate a payment request
|
|
224
|
+
|
|
225
|
+
const invoice = await client.createInvoice(node1Id, 42000, "Pizza!");
|
|
226
|
+
if (!invoice) {
|
|
227
|
+
throw new Error("Unable to create the invoice.");
|
|
228
|
+
}
|
|
229
|
+
console.log(`Invoice created from ${credentials.node1Name}:`);
|
|
230
|
+
console.log(`Encoded invoice = ${invoice}`);
|
|
231
|
+
console.log("");
|
|
232
|
+
|
|
233
|
+
// Decode the payment request
|
|
234
|
+
const decodedInvoice = await client.decodeInvoice(invoice);
|
|
235
|
+
if (!decodedInvoice) {
|
|
236
|
+
throw new Error("Unable to decode the invoice.");
|
|
237
|
+
}
|
|
238
|
+
console.log("Decoded payment request:");
|
|
239
|
+
console.log(
|
|
240
|
+
" destination public key = " + decodedInvoice.destination.publicKey
|
|
241
|
+
);
|
|
242
|
+
console.log(
|
|
243
|
+
" amount = " +
|
|
244
|
+
decodedInvoice.amount.preferredCurrencyValueApprox +
|
|
245
|
+
" " +
|
|
246
|
+
decodedInvoice.amount.preferredCurrencyUnit
|
|
247
|
+
);
|
|
248
|
+
console.log(" memo = " + decodedInvoice.memo);
|
|
249
|
+
console.log("");
|
|
250
|
+
|
|
251
|
+
// Let's send the payment.
|
|
252
|
+
|
|
253
|
+
// First, we need to recover the signing key.
|
|
254
|
+
await client.unlockNode(node2Id, credentials.node2Password!);
|
|
255
|
+
console.log(`${credentials.node2Name}'s signing key has been loaded.`);
|
|
256
|
+
|
|
257
|
+
// Then we can send the payment
|
|
258
|
+
const payment = await client.payInvoice(node2Id, invoice, 1000);
|
|
259
|
+
console.log(`Payment done with ID = ${payment.id}`);
|
|
260
|
+
console.log("");
|
|
261
|
+
|
|
262
|
+
const address = await client.createNodeWalletAddress(node1Id);
|
|
263
|
+
console.log(`Got a bitcoin address for ${credentials.node1Name}: ${address}`);
|
|
264
|
+
console.log("");
|
|
265
|
+
|
|
266
|
+
// const withdrawal = await client.requestWithdrawal(node2Id, 1000000, address, WithdrawalMode.WALLET_THEN_CHANNELS);
|
|
267
|
+
// console.log(`Money was withdrawn with ID = ${withdrawal.id}`);
|
|
268
|
+
// console.log("");
|
|
269
|
+
|
|
270
|
+
// Fetch the channels for Node 1
|
|
271
|
+
const node1 = await client.executeRawQuery(
|
|
272
|
+
LightsparkNode.getLightsparkNodeQuery(node1Id)
|
|
273
|
+
);
|
|
274
|
+
if (!node1) {
|
|
275
|
+
throw new Error("Unable to find node 1.");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const channelsConnection = await node1.getChannels(client, 10);
|
|
279
|
+
console.log(
|
|
280
|
+
`${credentials.node1Name} has ${channelsConnection.count} channel(s):`
|
|
281
|
+
);
|
|
282
|
+
for (const channel of channelsConnection.entities) {
|
|
283
|
+
if (channel.remoteNodeId) {
|
|
284
|
+
const remoteNode = await client.executeRawQuery(
|
|
285
|
+
Node.getNodeQuery(channel.remoteNodeId)
|
|
286
|
+
);
|
|
287
|
+
const alias = remoteNode?.alias ?? "UNKNOWN";
|
|
288
|
+
if (channel.localBalance && channel.remoteBalance) {
|
|
289
|
+
console.log(
|
|
290
|
+
` - With ${alias}. Local/remote balance = ${channel.localBalance.preferredCurrencyValueApprox} ${channel.localBalance.preferredCurrencyUnit}
|
|
291
|
+
/ ${channel.remoteBalance.preferredCurrencyValueApprox} ${channel.remoteBalance.preferredCurrencyUnit}`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
console.log("");
|