@tatumio/doge 2.2.19 → 2.2.20
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tatumio/doge",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.20",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./src/index.js",
|
6
6
|
"types": "./src/index.d.ts",
|
7
7
|
"dependencies": {
|
8
|
-
"@tatumio/shared-testing-common": "2.2.
|
9
|
-
"@tatumio/api-client": "2.2.
|
8
|
+
"@tatumio/shared-testing-common": "2.2.20",
|
9
|
+
"@tatumio/api-client": "2.2.20",
|
10
10
|
"axios": "^0.26.0",
|
11
11
|
"form-data": "^4.0.0",
|
12
|
-
"@tatumio/shared-testing-btc-based": "2.2.
|
13
|
-
"@tatumio/shared-blockchain-btc-based": "2.2.
|
14
|
-
"@tatumio/shared-abstract-sdk": "2.2.
|
12
|
+
"@tatumio/shared-testing-btc-based": "2.2.20",
|
13
|
+
"@tatumio/shared-blockchain-btc-based": "2.2.20",
|
14
|
+
"@tatumio/shared-abstract-sdk": "2.2.20",
|
15
15
|
"bignumber.js": "^9.0.2",
|
16
|
-
"@tatumio/shared-core": "2.2.
|
16
|
+
"@tatumio/shared-core": "2.2.20",
|
17
17
|
"lodash": "^4.17.21",
|
18
|
-
"@tatumio/shared-blockchain-abstract": "2.2.
|
18
|
+
"@tatumio/shared-blockchain-abstract": "2.2.20",
|
19
19
|
"bip32": "^2.0.5",
|
20
20
|
"bip39": "^3.0.2",
|
21
21
|
"bitcoinjs-lib": "^5.2.0",
|
@@ -3,8 +3,9 @@ export declare const DOGE_ERRORS_MAPPING: {
|
|
3
3
|
'dogecore.ErrorTransactionFeeErrorTooSmall': SdkErrorCode;
|
4
4
|
'dogecore.ErrorTransactionInvalidOutputAmountSum': SdkErrorCode;
|
5
5
|
'dogecore.ErrorTransactionFeeErrorDifferent': SdkErrorCode;
|
6
|
+
'dogecore.ErrorTransactionDustOutputs': SdkErrorCode;
|
6
7
|
};
|
7
|
-
export declare type DogeSdkErrorCode = SdkErrorCode.BTC_BASED_FEE_TOO_SMALL | SdkErrorCode.BTC_BASED_UTXO_NOT_FOUND | SdkErrorCode.BTC_BASED_NOT_ENOUGH_BALANCE;
|
8
|
+
export declare type DogeSdkErrorCode = SdkErrorCode.BTC_BASED_FEE_TOO_SMALL | SdkErrorCode.BTC_BASED_UTXO_NOT_FOUND | SdkErrorCode.BTC_BASED_NOT_ENOUGH_BALANCE | SdkErrorCode.BTC_BASED_DUST_AMOUNT | SdkErrorCode.BTC_BASED_NO_INPUTS | SdkErrorCode.BTC_BASED_WRONG_BODY;
|
8
9
|
export declare class DogeSdkError extends SdkError {
|
9
10
|
constructor(error: Error | DogeSdkErrorCode);
|
10
11
|
}
|
@@ -6,6 +6,7 @@ exports.DOGE_ERRORS_MAPPING = {
|
|
6
6
|
'dogecore.ErrorTransactionFeeErrorTooSmall': shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_FEE_TOO_SMALL,
|
7
7
|
'dogecore.ErrorTransactionInvalidOutputAmountSum': shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_NOT_ENOUGH_BALANCE,
|
8
8
|
'dogecore.ErrorTransactionFeeErrorDifferent': shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_FEE_TOO_SMALL,
|
9
|
+
'dogecore.ErrorTransactionDustOutputs': shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_DUST_AMOUNT,
|
9
10
|
};
|
10
11
|
class DogeSdkError extends shared_abstract_sdk_1.SdkError {
|
11
12
|
constructor(error) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"doge.sdk.errors.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/doge/src/lib/doge.sdk.errors.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAExD,QAAA,mBAAmB,GAAG;IACjC,2CAA2C,EAAE,kCAAY,CAAC,uBAAuB;IACjF,iDAAiD,EAAE,kCAAY,CAAC,4BAA4B;IAC5F,4CAA4C,EAAE,kCAAY,CAAC,uBAAuB;
|
1
|
+
{"version":3,"file":"doge.sdk.errors.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/doge/src/lib/doge.sdk.errors.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAExD,QAAA,mBAAmB,GAAG;IACjC,2CAA2C,EAAE,kCAAY,CAAC,uBAAuB;IACjF,iDAAiD,EAAE,kCAAY,CAAC,4BAA4B;IAC5F,4CAA4C,EAAE,kCAAY,CAAC,uBAAuB;IAClF,sCAAsC,EAAE,kCAAY,CAAC,qBAAqB;CAC3E,CAAA;AAUD,MAAa,YAAa,SAAQ,8BAAQ;IACxC,YAAY,KAA+B;QACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,KAAK,CAAC;gBACJ,IAAI,EAAE,KAAK;aACZ,CAAC,CAAA;SACH;aAAM;YACL,KAAK,CAAC;gBACJ,aAAa,EAAE,KAAK;gBACpB,qBAAqB,EAAE,2BAAmB;aAC3C,CAAC,CAAA;SACH;IACH,CAAC;CACF;AAbD,oCAaC"}
|
package/src/lib/doge.sdk.tx.js
CHANGED
@@ -7,6 +7,7 @@ const bitcore_lib_doge_1 = require("bitcore-lib-doge");
|
|
7
7
|
const api_client_1 = require("@tatumio/api-client");
|
8
8
|
const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
|
9
9
|
const doge_sdk_errors_1 = require("./doge.sdk.errors");
|
10
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
10
11
|
const dogeTransactions = (apiCalls = {
|
11
12
|
dogeBroadcast: api_client_1.ApiServices.blockchain.doge.dogeBroadcast,
|
12
13
|
getUTXOsByAddress: api_client_1.DataApiService.getUtxosByAddress,
|
@@ -15,22 +16,27 @@ const dogeTransactions = (apiCalls = {
|
|
15
16
|
const prepareSignedTransaction = (body, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
16
17
|
try {
|
17
18
|
const { to, fee, changeAddress } = body;
|
19
|
+
validateBody(body);
|
18
20
|
const transaction = new bitcore_lib_doge_1.Transaction();
|
19
|
-
const
|
20
|
-
let totalOutputs = shared_abstract_sdk_1.amountUtils.toSatoshis(fee);
|
21
|
+
const hasFeeAndChange = !lodash_1.default.isNil(changeAddress) && !lodash_1.default.isNil(fee);
|
22
|
+
let totalOutputs = hasFeeAndChange ? shared_abstract_sdk_1.amountUtils.toSatoshis(fee) : 0;
|
23
|
+
let totalInputs = 0;
|
21
24
|
for (const item of to) {
|
22
25
|
const amount = shared_abstract_sdk_1.amountUtils.toSatoshis(item.value);
|
23
26
|
totalOutputs += amount;
|
24
27
|
transaction.to(item.address, amount);
|
25
28
|
}
|
29
|
+
const privateKeysToSign = [];
|
26
30
|
if ('fromUTXO' in body) {
|
27
31
|
for (const item of body.fromUTXO) {
|
32
|
+
const satoshis = shared_abstract_sdk_1.amountUtils.toSatoshis(item.value);
|
33
|
+
totalInputs += satoshis;
|
28
34
|
transaction.from([
|
29
35
|
bitcore_lib_doge_1.Transaction.UnspentOutput.fromObject({
|
30
36
|
txId: item.txHash,
|
31
37
|
outputIndex: item.index,
|
32
38
|
script: bitcore_lib_doge_1.Script.fromAddress(item.address).toString(),
|
33
|
-
satoshis
|
39
|
+
satoshis,
|
34
40
|
}),
|
35
41
|
]);
|
36
42
|
if ('signatureId' in item)
|
@@ -40,7 +46,6 @@ const dogeTransactions = (apiCalls = {
|
|
40
46
|
}
|
41
47
|
}
|
42
48
|
else if ('fromAddress' in body) {
|
43
|
-
let totalInputs = 0;
|
44
49
|
for (const item of body.fromAddress) {
|
45
50
|
if (totalInputs >= totalOutputs) {
|
46
51
|
break;
|
@@ -64,7 +69,12 @@ const dogeTransactions = (apiCalls = {
|
|
64
69
|
}
|
65
70
|
}
|
66
71
|
}
|
67
|
-
|
72
|
+
if (hasFeeAndChange) {
|
73
|
+
transaction.change(changeAddress);
|
74
|
+
transaction.fee(shared_abstract_sdk_1.amountUtils.toSatoshis(fee));
|
75
|
+
}
|
76
|
+
const shouldHaveChangeOutput = totalInputs > totalOutputs && hasFeeAndChange;
|
77
|
+
checkDustAmountInChange(transaction, body, shouldHaveChangeOutput);
|
68
78
|
if ('fromUTXO' in body && 'signatureId' in body.fromUTXO[0] && body.fromUTXO[0].signatureId) {
|
69
79
|
return JSON.stringify(transaction);
|
70
80
|
}
|
@@ -80,16 +90,29 @@ const dogeTransactions = (apiCalls = {
|
|
80
90
|
throw new doge_sdk_errors_1.DogeSdkError(e);
|
81
91
|
}
|
82
92
|
});
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
const validateBody = (body) => {
|
94
|
+
if (!('fromUTXO' in body) && !('fromAddress' in body)) {
|
95
|
+
throw new doge_sdk_errors_1.DogeSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_WRONG_BODY);
|
96
|
+
}
|
97
|
+
if (('fromUTXO' in body && lodash_1.default.isEmpty(body.fromUTXO)) ||
|
98
|
+
('fromAddress' in body && lodash_1.default.isEmpty(body.fromAddress))) {
|
99
|
+
throw new doge_sdk_errors_1.DogeSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_NO_INPUTS);
|
100
|
+
}
|
101
|
+
if ((body.fee && !body.changeAddress) || (!body.fee && body.changeAddress)) {
|
102
|
+
throw new doge_sdk_errors_1.DogeSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_WRONG_BODY);
|
103
|
+
}
|
104
|
+
};
|
105
|
+
/**
|
106
|
+
* In case if change amount is dust, its amount will be appended to fee.
|
107
|
+
* We need to check it to prevent implicit amounts change
|
108
|
+
*/
|
109
|
+
const checkDustAmountInChange = (transaction, body, shouldHaveChangeOutput) => {
|
110
|
+
const outputsCount = transaction.outputs.length;
|
111
|
+
const expectedOutputsCount = body.to.length + (shouldHaveChangeOutput ? 1 : 0);
|
112
|
+
if (outputsCount !== expectedOutputsCount) {
|
113
|
+
throw new doge_sdk_errors_1.DogeSdkError(shared_abstract_sdk_1.SdkErrorCode.BTC_BASED_DUST_AMOUNT);
|
114
|
+
}
|
115
|
+
};
|
93
116
|
const sendTransaction = (body, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
94
117
|
return apiCalls.dogeBroadcast({
|
95
118
|
txData: yield prepareSignedTransaction(body, options),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"doge.sdk.tx.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/doge/src/lib/doge.sdk.tx.ts"],"names":[],"mappings":";;;;AAAA,aAAa;AACb,uDAAkE;AAClE,
|
1
|
+
{"version":3,"file":"doge.sdk.tx.js","sourceRoot":"","sources":["../../../../../../packages/blockchain/doge/src/lib/doge.sdk.tx.ts"],"names":[],"mappings":";;;;AAAA,aAAa;AACb,uDAAkE;AAClE,oDAQ4B;AAE5B,sEAAwE;AACxE,uDAAgD;AAChD,4DAAsB;AAUf,MAAM,gBAAgB,GAAG,CAC9B,WAII;IACF,aAAa,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa;IACxD,iBAAiB,EAAE,2BAAc,CAAC,iBAAiB;IACnD,OAAO,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW;CACjD,EACiC,EAAE;IACpC,MAAM,wBAAwB,GAAG,CAC/B,IAA0B,EAC1B,OAAsB,EACL,EAAE;QACnB,IAAI;YACF,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;YACvC,YAAY,CAAC,IAAI,CAAC,CAAA;YAClB,MAAM,WAAW,GAAG,IAAI,8BAAW,EAAE,CAAA;YAErC,MAAM,eAAe,GAAG,CAAC,gBAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAChE,IAAI,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,iCAAW,C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