@tatumio/doge 2.1.17 → 2.1.18

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.17",
3
+ "version": "2.1.18",
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.17",
9
- "@tatumio/api-client": "2.1.17",
8
+ "@tatumio/shared-testing-common": "2.1.18",
9
+ "@tatumio/api-client": "2.1.18",
10
10
  "axios": "^0.26.0",
11
11
  "form-data": "^4.0.0",
12
- "@tatumio/shared-testing-btc-based": "2.1.17",
13
- "@tatumio/shared-blockchain-btc-based": "2.1.17",
14
- "@tatumio/shared-abstract-sdk": "2.1.17",
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",
15
15
  "bignumber.js": "^9.0.2",
16
- "@tatumio/shared-core": "2.1.17",
16
+ "@tatumio/shared-core": "2.1.18",
17
17
  "lodash": "^4.17.21",
18
- "@tatumio/shared-blockchain-abstract": "2.1.17",
18
+ "@tatumio/shared-blockchain-abstract": "2.1.18",
19
19
  "bip32": "^2.0.5",
20
20
  "bip39": "^3.0.2",
21
21
  "bitcoinjs-lib": "^5.2.0",
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './lib/doge.sdk';
2
2
  export { DogeTransactionTypes, dogeTransactions } from './lib/doge.sdk.tx';
3
3
  export { dogeWallet } from './lib/doge.sdk.wallet';
4
+ export { DogeTransactionAddress } from './lib/doge.sdk.tx';
@@ -1,6 +1,30 @@
1
1
  import { ApiServices, DogeTransactionUTXO, DogeTransactionUTXOKMS } from '@tatumio/api-client';
2
2
  import { BtcBasedTx } from '@tatumio/shared-blockchain-btc-based';
3
- export declare type DogeTransactionTypes = DogeTransactionUTXO | DogeTransactionUTXOKMS;
3
+ interface DogeTransactionBase {
4
+ to: Array<{
5
+ address: string;
6
+ value: number;
7
+ }>;
8
+ fee?: string;
9
+ changeAddress?: string;
10
+ }
11
+ export interface DogeTransactionAddress extends DogeTransactionBase {
12
+ fromAddress: {
13
+ address: string;
14
+ privateKey: string;
15
+ }[];
16
+ }
17
+ interface DogeTransactionAddressKMS extends DogeTransactionBase {
18
+ fromAddress: {
19
+ address: string;
20
+ signatureId: string;
21
+ index?: number;
22
+ }[];
23
+ }
24
+ export declare type DogeTransactionTypes = DogeTransactionUTXO | DogeTransactionUTXOKMS | DogeTransactionAddress | DogeTransactionAddressKMS;
4
25
  export declare const dogeTransactions: (apiCalls?: {
5
26
  dogeBroadcast: typeof ApiServices.blockchain.doge.dogeBroadcast;
27
+ getTxByAddress: typeof ApiServices.blockchain.doge.dogeGetTxByAddress;
28
+ getUtxo: typeof ApiServices.blockchain.doge.dogeGetUtxo;
6
29
  }) => BtcBasedTx<DogeTransactionTypes>;
30
+ export {};
@@ -9,41 +9,90 @@ const shared_abstract_sdk_1 = require("@tatumio/shared-abstract-sdk");
9
9
  const doge_sdk_errors_1 = require("./doge.sdk.errors");
10
10
  const dogeTransactions = (apiCalls = {
11
11
  dogeBroadcast: api_client_1.ApiServices.blockchain.doge.dogeBroadcast,
12
+ getTxByAddress: api_client_1.ApiServices.blockchain.doge.dogeGetTxByAddress,
13
+ getUtxo: api_client_1.ApiServices.blockchain.doge.dogeGetUtxo,
12
14
  }) => {
13
15
  // @TODO add support - by address
14
16
  const prepareSignedTransaction = (body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
15
17
  try {
16
- const { fromUTXO, to, fee, changeAddress } = body;
17
- const tx = new bitcore_lib_doge_1.Transaction();
18
+ const { to, fee, changeAddress } = body;
19
+ const transaction = new bitcore_lib_doge_1.Transaction();
18
20
  const privateKeysToSign = [];
19
- for (const item of fromUTXO) {
20
- tx.from({
21
- txId: item.txHash,
22
- outputIndex: item.index,
23
- script: bitcore_lib_doge_1.Script.fromAddress(item.address).toString(),
24
- satoshis: shared_abstract_sdk_1.amountUtils.toSatoshis(item.value),
25
- });
26
- if ('signatureId' in item)
27
- privateKeysToSign.push(item.signatureId);
28
- else if ('privateKey' in item)
29
- privateKeysToSign.push(item.privateKey);
21
+ if ('fromUTXO' in body) {
22
+ for (const item of body.fromUTXO) {
23
+ transaction.from({
24
+ txId: item.txHash,
25
+ outputIndex: item.index,
26
+ script: bitcore_lib_doge_1.Script.fromAddress(item.address).toString(),
27
+ satoshis: shared_abstract_sdk_1.amountUtils.toSatoshis(item.value),
28
+ });
29
+ if ('signatureId' in item)
30
+ privateKeysToSign.push(item.signatureId);
31
+ else if ('privateKey' in item)
32
+ privateKeysToSign.push(item.privateKey);
33
+ }
34
+ }
35
+ else if ('fromAddress' in body) {
36
+ for (const item of body.fromAddress) {
37
+ const utxos = [];
38
+ const txs = yield apiCalls.getTxByAddress(item.address, 50, 0, 'incoming');
39
+ for (const tx of txs) {
40
+ if (!tx.outputs || !tx.hash)
41
+ continue;
42
+ for (const [i, o] of tx.outputs.entries()) {
43
+ if (o.address !== item.address) {
44
+ continue;
45
+ }
46
+ const utxo = yield getUtxoSilent(tx.hash, i);
47
+ if (utxo === null) {
48
+ continue;
49
+ }
50
+ utxos.push(utxo);
51
+ transaction.from([
52
+ bitcore_lib_doge_1.Transaction.UnspentOutput.fromObject({
53
+ txId: tx.hash,
54
+ outputIndex: i,
55
+ script: bitcore_lib_doge_1.Script.fromAddress(o.address).toString(),
56
+ satoshis: shared_abstract_sdk_1.amountUtils.toSatoshis(utxo.value),
57
+ }),
58
+ ]);
59
+ if ('signatureId' in item)
60
+ privateKeysToSign.push(item.signatureId);
61
+ else if ('privateKey' in item)
62
+ privateKeysToSign.push(item.privateKey);
63
+ }
64
+ }
65
+ }
30
66
  }
31
67
  for (const item of to) {
32
- tx.to(item.address, shared_abstract_sdk_1.amountUtils.toSatoshis(item.value));
68
+ transaction.to(item.address, shared_abstract_sdk_1.amountUtils.toSatoshis(item.value));
69
+ }
70
+ transaction.fee(shared_abstract_sdk_1.amountUtils.toSatoshis(fee)).change(changeAddress);
71
+ if ('fromUTXO' in body && 'signatureId' in body.fromUTXO[0] && body.fromUTXO[0].signatureId) {
72
+ return JSON.stringify(transaction);
33
73
  }
34
- tx.fee(shared_abstract_sdk_1.amountUtils.toSatoshis(fee)).change(changeAddress);
35
- if (fromUTXO && 'signatureId' in fromUTXO[0] && fromUTXO[0].signatureId) {
36
- return JSON.stringify(tx);
74
+ if ('fromAddress' in body && 'signatureId' in body.fromAddress[0] && body.fromAddress[0].signatureId) {
75
+ return JSON.stringify(transaction);
37
76
  }
38
77
  for (const pk of privateKeysToSign) {
39
- tx.sign(bitcore_lib_doge_1.PrivateKey.fromWIF(pk));
78
+ transaction.sign(bitcore_lib_doge_1.PrivateKey.fromWIF(pk));
40
79
  }
41
- return tx.serialize();
80
+ return transaction.serialize();
42
81
  }
43
82
  catch (e) {
44
83
  throw new doge_sdk_errors_1.DogeSdkError(e);
45
84
  }
46
85
  });
86
+ function getUtxoSilent(hash, i) {
87
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
+ try {
89
+ return yield apiCalls.getUtxo(hash, i);
90
+ }
91
+ catch (e) {
92
+ return null;
93
+ }
94
+ });
95
+ }
47
96
  const sendTransaction = (body) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
48
97
  return apiCalls.dogeBroadcast({
49
98
  txData: yield prepareSignedTransaction(body),
@@ -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,oDAA+G;AAE/G,sEAA0D;AAC1D,uDAAgD;AAIzC,MAAM,gBAAgB,GAAG,CAC9B,WAEI;IACF,aAAa,EAAE,wBAAW,CAAC,UAAU,CAAC,IAAI,CAAC,aAAa;CACzD,EACiC,EAAE;IACpC,iCAAiC;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