Skip to content

Commit 39fe6fa

Browse files
author
AJ ONeal
committed
ref!: migrate from dashcore-lib to blocktx
1 parent be272ba commit 39fe6fa

File tree

9 files changed

+580
-2006
lines changed

9 files changed

+580
-2006
lines changed

bin/crowdnode.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let Prompt = require("./_prompt.js");
2121
let Qr = require("./_qr-node.js");
2222
let Ws = require("dashsight/ws");
2323

24-
let Dashcore = require("@dashevo/dashcore-lib");
24+
let Dashcore = require("../dashcore-lit.js");
2525

2626
const DONE = "✅";
2727
const TODO = "ℹ️";
@@ -663,7 +663,7 @@ async function mustGetAddr({ defaultAddr }, args) {
663663
return [addr, name];
664664
}
665665
//let pk = new Dashcore.PrivateKey(wif);
666-
//let addr = pk.toAddress().toString();
666+
//let addr = (await pk.toAddress()).toString();
667667
return [addr, name];
668668
}
669669

@@ -796,8 +796,8 @@ async function generateKey({ defaultKey, plainText }, args) {
796796
//@ts-ignore - TODO submit JSDoc PR for Dashcore
797797
let pk = new Dashcore.PrivateKey();
798798

799-
let addr = pk.toAddress().toString();
800-
let plainWif = pk.toWIF();
799+
let addr = (await pk.toAddress()).toString();
800+
let plainWif = await pk.toWIF();
801801

802802
let wif = plainWif;
803803
if (!plainText) {
@@ -1259,7 +1259,7 @@ async function maybeReadKeyFileRaw(filepath, opts) {
12591259
}
12601260

12611261
let pk = new Dashcore.PrivateKey(privKey);
1262-
let pub = pk.toAddress().toString();
1262+
let pub = (await pk.toAddress()).toString();
12631263

12641264
return {
12651265
addr: pub,
@@ -1326,7 +1326,7 @@ async function setDefault(_, args) {
13261326
let filepath = Path.join(keysDir, keyname);
13271327
let wif = await maybeReadKeyFile(filepath);
13281328
let pk = new Dashcore.PrivateKey(wif);
1329-
let pub = pk.toAddress().toString();
1329+
let pub = (await pk.toAddress()).toString();
13301330

13311331
console.info("set", defaultWifPath, pub);
13321332
await Fs.writeFile(defaultWifPath, pub, "utf8");
@@ -1439,7 +1439,7 @@ async function getAllBalances({ dashApi, defaultAddr }, args) {
14391439

14401440
/*
14411441
let pk = new Dashcore.PrivateKey(wif);
1442-
let pub = pk.toAddress().toString();
1442+
let pub = (await pk.toAddress()).toString();
14431443
if (`${pub}.wif` !== wifname) {
14441444
// sanity check
14451445
warns.push({
@@ -2038,12 +2038,11 @@ async function wifFileToAddr(name) {
20382038
}
20392039

20402040
let pk = new Dashcore.PrivateKey(privKey);
2041-
let pub = pk.toPublicKey().toAddress().toString();
2041+
let pub = (await pk.toPublicKey().toAddress()).toString();
20422042
return pub;
20432043
}
20442044

20452045
/**
2046-
* @param {String} insightBaseUrl
20472046
* @param {String} addr
20482047
*/
20492048
async function collectSignupFees(addr) {

crowdnode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
const DUFFS = 100000000;
1313

1414
let Dash = exports.DashApi || require("./dashapi.js");
15-
let Dashcore = exports.dashcore || require("./lib/dashcore.js");
15+
let Dashcore = exports.dashcore || require("./dashcore-lit.js");
1616
let DashSight = exports.DashSight || require("dashsight");
1717
let Ws = exports.DashSocket || require("dashsight/ws");
1818

@@ -189,7 +189,7 @@
189189
// Send Request Message
190190
let pk = new Dashcore.PrivateKey(wif);
191191
let msg = CrowdNode.offset + CrowdNode.requests.signupForApi;
192-
let changeAddr = pk.toPublicKey().toAddress().toString();
192+
let changeAddr = (await pk.toPublicKey().toAddress()).toString();
193193
let tx = await CrowdNode._dashApi.createPayment(
194194
wif,
195195
hotwallet,
@@ -214,7 +214,7 @@
214214
// Send Request Message
215215
let pk = new Dashcore.PrivateKey(wif);
216216
let msg = CrowdNode.offset + CrowdNode.requests.acceptTerms;
217-
let changeAddr = pk.toPublicKey().toAddress().toString();
217+
let changeAddr = (await pk.toPublicKey().toAddress()).toString();
218218
let tx = await CrowdNode._dashApi.createPayment(
219219
wif,
220220
hotwallet,
@@ -240,7 +240,7 @@
240240
CrowdNode.deposit = async function (wif, hotwallet, amount) {
241241
// Send Request Message
242242
let pk = new Dashcore.PrivateKey(wif);
243-
let changeAddr = pk.toPublicKey().toAddress().toString();
243+
let changeAddr = (await pk.toPublicKey().toAddress()).toString();
244244

245245
// TODO reserve a balance
246246
let tx;
@@ -279,7 +279,7 @@
279279
// Send Request Message
280280
let pk = new Dashcore.PrivateKey(wif);
281281
let msg = CrowdNode.offset + permil;
282-
let changeAddr = pk.toPublicKey().toAddress().toString();
282+
let changeAddr = (await pk.toPublicKey().toAddress()).toString();
283283
let tx = await CrowdNode._dashApi.createPayment(
284284
wif,
285285
hotwallet,

dashapi.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
exports.DashApi = Dash;
77

88
const DUFFS = 100000000;
9-
const DUST = 10000;
109
const FEE = 1000;
1110

1211
//@ts-ignore
13-
let Dashcore = exports.dashcore || require("./lib/dashcore.js");
12+
let Dashcore = exports.dashcore || require("./dashcore-lit.js");
1413
let Transaction = Dashcore.Transaction;
14+
let PrivateKey = Dashcore.PrivateKey;
1515

1616
Dash.create = function ({
1717
//@ts-ignore TODO
@@ -51,8 +51,8 @@
5151
* @param {String} pub
5252
*/
5353
dashApi.createBalanceTransfer = async function (privKey, pub) {
54-
let pk = new Dashcore.PrivateKey(privKey);
55-
let changeAddr = pk.toPublicKey().toAddress().toString();
54+
let pk = new PrivateKey(privKey);
55+
let changeAddr = (await pk.toPublicKey().toAddress()).toString();
5656

5757
let body = await insightApi.getUtxos(changeAddr);
5858
let utxos = await getUtxos(body);
@@ -65,7 +65,7 @@
6565
//@ts-ignore - allows single value or array
6666
.from(utxos);
6767
tmpTx.to(pub, balance - 1000);
68-
tmpTx.sign(pk);
68+
await tmpTx.sign(pk);
6969

7070
// TODO getsmartfeeestimate??
7171
// fee = 1duff/byte (2 chars hex is 1 byte)
@@ -78,26 +78,26 @@
7878
.from(utxos);
7979
tx.to(pub, balance - fee);
8080
tx.fee(fee);
81-
tx.sign(pk);
81+
await tx.sign(pk);
8282

8383
return tx;
8484
};
8585

8686
/**
8787
* Send with change back
8888
* @param {String} privKey
89-
* @param {(String|import('@dashevo/dashcore-lib').Address)} payAddr
89+
* @param {String} payAddr
9090
* @param {Number} amount
91-
* @param {(String|import('@dashevo/dashcore-lib').Address)} [changeAddr]
91+
* @param {String} [changeAddr]
9292
*/
9393
dashApi.createPayment = async function (
9494
privKey,
9595
payAddr,
9696
amount,
9797
changeAddr,
9898
) {
99-
let pk = new Dashcore.PrivateKey(privKey);
100-
let utxoAddr = pk.toPublicKey().toAddress().toString();
99+
let pk = new PrivateKey(privKey);
100+
let utxoAddr = (await pk.toPublicKey().toAddress()).toString();
101101
if (!changeAddr) {
102102
changeAddr = utxoAddr;
103103
}
@@ -112,7 +112,7 @@
112112
}
113113

114114
// (estimate) don't send dust back as change
115-
if (balance - amount <= DUST + FEE) {
115+
if (balance - amount <= Transaction.DUST_AMOUNT + FEE) {
116116
amount = balance;
117117
}
118118

@@ -123,7 +123,7 @@
123123
tmpTx.to(payAddr, amount);
124124
//@ts-ignore - the JSDoc is wrong in dashcore-lib/lib/transaction/transaction.js
125125
tmpTx.change(changeAddr);
126-
tmpTx.sign(pk);
126+
await tmpTx.sign(pk);
127127

128128
// TODO getsmartfeeestimate??
129129
// fee = 1duff/byte (2 chars hex is 1 byte)
@@ -132,7 +132,7 @@
132132
let fee = 10 + tmpTx.toString().length / 2;
133133

134134
// (adjusted) don't send dust back as change
135-
if (balance + -amount + -fee <= DUST) {
135+
if (balance + -amount + -fee <= Transaction.DUST_AMOUNT) {
136136
amount = balance - fee;
137137
}
138138

@@ -144,7 +144,7 @@
144144
tx.fee(fee);
145145
//@ts-ignore - see above
146146
tx.change(changeAddr);
147-
tx.sign(pk);
147+
await tx.sign(pk);
148148

149149
return tx;
150150
};

0 commit comments

Comments
 (0)