@tatumio/doge 2.1.18 → 2.1.19

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.1.18",
3
+ "version": "2.1.19",
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.1.18",
9
- "@tatumio/api-client": "2.1.18",
8
+ "@tatumio/shared-testing-common": "2.1.19",
9
+ "@tatumio/api-client": "2.1.19",
10
10
  "axios": "^0.26.0",
11
11
  "form-data": "^4.0.0",
12
- "@tatumio/shared-testing-btc-based": "2.1.18",
13
- "@tatumio/shared-blockchain-btc-based": "2.1.18",
14
- "@tatumio/shared-abstract-sdk": "2.1.18",
12
+ "@tatumio/shared-testing-btc-based": "2.1.19",
13
+ "@tatumio/shared-blockchain-btc-based": "2.1.19",
14
+ "@tatumio/shared-abstract-sdk": "2.1.19",
15
15
  "bignumber.js": "^9.0.2",
16
- "@tatumio/shared-core": "2.1.18",
16
+ "@tatumio/shared-core": "2.1.19",
17
17
  "lodash": "^4.17.21",
18
- "@tatumio/shared-blockchain-abstract": "2.1.18",
18
+ "@tatumio/shared-blockchain-abstract": "2.1.19",
19
19
  "bip32": "^2.0.5",
20
20
  "bip39": "^3.0.2",
21
21
  "bitcoinjs-lib": "^5.2.0",
@@ -12,12 +12,17 @@ const dogeTransactions = (apiCalls = {
12
12
  getTxByAddress: api_client_1.ApiServices.blockchain.doge.dogeGetTxByAddress,
13
13
  getUtxo: api_client_1.ApiServices.blockchain.doge.dogeGetUtxo,
14
14
  }) => {
15
- // @TODO add support - by address
16
15
  const prepareSignedTransaction = (body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
17
16
  try {
18
17
  const { to, fee, changeAddress } = body;
19
18
  const transaction = new bitcore_lib_doge_1.Transaction();
20
19
  const privateKeysToSign = [];
20
+ let totalOutputs = shared_abstract_sdk_1.amountUtils.toSatoshis(fee);
21
+ for (const item of to) {
22
+ const amount = shared_abstract_sdk_1.amountUtils.toSatoshis(item.value);
23
+ totalOutputs += amount;
24
+ transaction.to(item.address, amount);
25
+ }
21
26
  if ('fromUTXO' in body) {
22
27
  for (const item of body.fromUTXO) {
23
28
  transaction.from({
@@ -33,27 +38,39 @@ const dogeTransactions = (apiCalls = {
33
38
  }
34
39
  }
35
40
  else if ('fromAddress' in body) {
41
+ let totalInputs = 0;
36
42
  for (const item of body.fromAddress) {
37
43
  const utxos = [];
38
44
  const txs = yield apiCalls.getTxByAddress(item.address, 50, 0, 'incoming');
45
+ if (totalInputs >= totalOutputs) {
46
+ break;
47
+ }
39
48
  for (const tx of txs) {
49
+ if (totalInputs >= totalOutputs) {
50
+ break;
51
+ }
40
52
  if (!tx.outputs || !tx.hash)
41
53
  continue;
42
54
  for (const [i, o] of tx.outputs.entries()) {
43
55
  if (o.address !== item.address) {
44
56
  continue;
45
57
  }
58
+ if (totalInputs >= totalOutputs) {
59
+ break;
60
+ }
46
61
  const utxo = yield getUtxoSilent(tx.hash, i);
47
62
  if (utxo === null) {
48
63
  continue;
49
64
  }
50
65
  utxos.push(utxo);
66
+ const satoshis = shared_abstract_sdk_1.amountUtils.toSatoshis(utxo.value);
67
+ totalInputs += satoshis;
51
68
  transaction.from([
52
69
  bitcore_lib_doge_1.Transaction.UnspentOutput.fromObject({
53
70
  txId: tx.hash,
54
71
  outputIndex: i,
55
72
  script: bitcore_lib_doge_1.Script.fromAddress(o.address).toString(),
56
- satoshis: shared_abstract_sdk_1.amountUtils.toSatoshis(utxo.value),
73
+ satoshis,
57
74
  }),
58
75
  ]);
59
76
  if ('signatureId' in item)
@@ -64,9 +81,6 @@ const dogeTransactions = (apiCalls = {
64
81
  }
65
82
  }
66
83
  }
67
- for (const item of to) {
68
- transaction.to(item.address, shared_abstract_sdk_1.amountUtils.toSatoshis(item.value));
69
- }
70
84
  transaction.fee(shared_abstract_sdk_1.amountUtils.toSatoshis(fee)).change(changeAddress);
71
85
  if ('fromUTXO' in body && 'signatureId' in body.fromUTXO[0] && body.fromUTXO[0].signatureId) {
72
86
  return JSON.stringify(transaction);
@@ -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,oDAM4B;AAE5B,sEAA0D;AAC1D,uDAAgD;AAgCzC,MAAM,gBAAgB,GAAG,CAC9B,WAII;IACF,aAAa,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa;IACxD,cAAc,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,kBAAkB;IAC9D,OAAO,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW;CACjD,EACiC,EAAE;IACpC,iCAAiC;IACjC,MAAM,wBAAwB,GAAG,CAAO,IAA0B,EAAmB,EAAE;QACrF,IAAI;YACF,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;YACvC,MAAM,WAAW,GAAG,IAAI,8BAAW,EAAE,CAAA;YAErC,MAAM,iBAAiB,GAAG,EAAE,CAAA;YAE5B,IAAI,UAAU,IAAI,IAAI,EAAE;gBACtB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;oBAChC,WAAW,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,IAAI,CAAC,MAAM;wBACjB,WAAW,EAAE,IAAI,CAAC,KAAK;wBACvB,MAAM,EAAE,yBAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE;wBACnD,QAAQ,EAAE,iCAAW,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;qBAC7C,CAAC,CAAA;oBACF,IAAI,aAAa,IAAI,IAAI;wBAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,WAA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