Skip to content

Commit fc4716e

Browse files
committed
update rgb-lib to 0.3.0-alpha.10 + fixes/improvements
1 parent 3864bc6 commit fc4716e

File tree

5 files changed

+230
-80
lines changed

5 files changed

+230
-80
lines changed

example.js

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function checkMemoryLeak() {
3232
}
3333
}
3434

35-
function initWallet() {
35+
function initWallet(vanillaKeychain) {
3636
let bitcoinNetwork = rgblib.BitcoinNetwork.Regtest;
3737
let keys = rgblib.generateKeys(bitcoinNetwork);
3838
console.log("Keys: " + JSON.stringify(keys));
@@ -44,10 +44,10 @@ function initWallet() {
4444
dataDir: "./data",
4545
bitcoinNetwork: bitcoinNetwork,
4646
databaseType: rgblib.DatabaseType.Sqlite,
47-
maxAllocationsPerUtxo: 1,
47+
maxAllocationsPerUtxo: "1",
4848
pubkey: keys.accountXpub,
4949
mnemonic: keys.mnemonic,
50-
vanillaKeychain: null,
50+
vanillaKeychain: vanillaKeychain,
5151
};
5252
console.log("Creating wallet...");
5353
let wallet = new rgblib.Wallet(new rgblib.WalletData(walletData));
@@ -68,27 +68,37 @@ function initWallet() {
6868
btcBalance = wallet.getBtcBalance(online, false);
6969
console.log("BTC balance: " + btcBalance);
7070

71-
let created = wallet.createUtxos(online, false, 25, null, 1.5, false);
71+
let created = wallet.createUtxos(online, false, "25", null, "1.0", false);
7272
console.log("Created " + created + " UTXOs");
7373

7474
return [wallet, online];
7575
}
7676

7777
function main() {
78-
let [wallet, online] = initWallet();
78+
let [wallet, online] = initWallet(null);
7979

80-
let asset1 = wallet.issueAssetNIA(online, "USDT", "Tether", 2, [777, 66]);
80+
let asset1 = wallet.issueAssetNIA(online, "USDT", "Tether", "2", [
81+
"777",
82+
"66",
83+
]);
8184
console.log("Issued a NIA asset " + JSON.stringify(asset1));
8285

83-
let asset2 = wallet.issueAssetCFA(online, "Cfa", "desc", 2, [777], null);
86+
let asset2 = wallet.issueAssetCFA(
87+
online,
88+
"Cfa",
89+
"desc",
90+
"2",
91+
["777"],
92+
null,
93+
);
8494
console.log("Issued a CFA asset: " + JSON.stringify(asset2));
8595

8696
let asset3 = wallet.issueAssetUDA(
8797
online,
8898
"TKN",
8999
"Token",
90100
null,
91-
2,
101+
"2",
92102
"README.md",
93103
[],
94104
);
@@ -103,23 +113,56 @@ function main() {
103113
let assets2 = wallet.listAssets([]);
104114
console.log("Assets: " + JSON.stringify(assets2));
105115

106-
let [rcvWallet, rcvOnline] = initWallet();
116+
let [rcvWallet, rcvOnline] = initWallet("3");
117+
118+
let receiveData1 = rcvWallet.blindReceive(
119+
null,
120+
"100",
121+
null,
122+
[PROXY_URL],
123+
"1",
124+
);
125+
console.log("Receive data: " + JSON.stringify(receiveData1));
107126

108-
let receiveData = rcvWallet.blindReceive(null, 100, null, [PROXY_URL], 1);
109-
console.log("Receive data: " + JSON.stringify(receiveData));
127+
let receiveData2 = rcvWallet.witnessReceive(
128+
null,
129+
"50",
130+
"60",
131+
[PROXY_URL],
132+
"1",
133+
);
134+
console.log("Receive data: " + JSON.stringify(receiveData2));
110135

111136
let recipientMap = {
112137
[asset1.assetId]: [
113138
{
114-
recipientId: receiveData.recipientId,
139+
recipientId: receiveData1.recipientId,
115140
witnessData: null,
116-
amount: 100,
141+
amount: "100",
142+
transportEndpoints: [PROXY_URL],
143+
},
144+
],
145+
[asset2.assetId]: [
146+
{
147+
recipientId: receiveData2.recipientId,
148+
witnessData: {
149+
amountSat: "1500",
150+
blinding: null,
151+
},
152+
amount: "50",
117153
transportEndpoints: [PROXY_URL],
118154
},
119155
],
120156
};
121157

122-
let sendResult = wallet.send(online, recipientMap, false, 1.3, 1, false);
158+
let sendResult = wallet.send(
159+
online,
160+
recipientMap,
161+
false,
162+
"1.3",
163+
"1",
164+
false,
165+
);
123166
console.log("Sent: " + JSON.stringify(sendResult));
124167

125168
rcvWallet.refresh(rcvOnline, null, [], false);
@@ -148,12 +191,21 @@ function main() {
148191
console.log("Unspents: " + JSON.stringify(unspents));
149192

150193
try {
151-
let feeEstimation = wallet.getFeeEstimation(online, 7);
194+
let feeEstimation = wallet.getFeeEstimation(online, "7");
152195
console.log("Fee estimation: " + JSON.stringify(feeEstimation));
153196
} catch (e) {
154197
console.log("Error getting fee estimation: " + e);
155198
}
156199

200+
let txid = wallet.sendBtc(
201+
online,
202+
rcvWallet.getAddress(),
203+
"700",
204+
"1.6",
205+
false,
206+
);
207+
console.log("Sent BTC, txid: " + txid);
208+
157209
// these avoid memory leaks, unnecessary here since the program exits
158210
rgblib.dropOnline(online);
159211
wallet.drop();

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"author": "Zoe Faltibà <[email protected]>",
2828
"license": "MIT",
2929
"dependencies": {
30+
"big.js": "^6.2.2",
3031
"node-addon-api": "^7.0.0",
3132
"node-gyp": "^9.4.0"
3233
},

0 commit comments

Comments
 (0)