@ledgerhq/coin-xrp 0.9.2 → 1.0.0-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +11 -10
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +35 -36
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +65 -50
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +66 -44
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/broadcast.js +3 -12
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +9 -14
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.js +4 -13
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -13
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.js +60 -68
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronization.js +32 -45
- package/lib/bridge/synchronization.js.map +1 -1
- package/lib/bridge/synchronization.test.js +21 -17
- package/lib/bridge/synchronization.test.js.map +1 -1
- package/lib/bridge/transaction.js +16 -4
- package/lib/bridge/transaction.js.map +1 -1
- package/lib/logic/broadcast.js +8 -19
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/broadcast.test.js +6 -15
- package/lib/logic/broadcast.test.js.map +1 -1
- package/lib/logic/combine.js +2 -2
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/craftTransaction.js +28 -34
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +8 -17
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.js +17 -28
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/estimateFees.test.js +10 -19
- package/lib/logic/estimateFees.test.js.map +1 -1
- package/lib/logic/getBalance.js +3 -14
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBalance.test.js +4 -13
- package/lib/logic/getBalance.test.js.map +1 -1
- package/lib/logic/lastBlock.js +7 -18
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts +15 -5
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +84 -71
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +66 -62
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/logic/utils.js +9 -18
- package/lib/logic/utils.js.map +1 -1
- package/lib/logic/utils.test.js +9 -18
- package/lib/logic/utils.test.js.map +1 -1
- package/lib/network/index.d.ts +6 -3
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +40 -48
- package/lib/network/index.js.map +1 -1
- package/lib/network/index.test.js +9 -18
- package/lib/network/index.test.js.map +1 -1
- package/lib/network/types.d.ts +5 -0
- package/lib/network/types.d.ts.map +1 -1
- package/lib/network/types.js.map +1 -1
- package/lib/signer/getAddress.js +3 -12
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/test/cli.js +5 -1
- package/lib/test/cli.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +35 -36
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +65 -50
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +66 -44
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/broadcast.js +3 -12
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +9 -14
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +4 -13
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -13
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.js +60 -68
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronization.js +32 -45
- package/lib-es/bridge/synchronization.js.map +1 -1
- package/lib-es/bridge/synchronization.test.js +21 -17
- package/lib-es/bridge/synchronization.test.js.map +1 -1
- package/lib-es/bridge/transaction.js +16 -4
- package/lib-es/bridge/transaction.js.map +1 -1
- package/lib-es/logic/broadcast.js +8 -19
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/broadcast.test.js +6 -15
- package/lib-es/logic/broadcast.test.js.map +1 -1
- package/lib-es/logic/combine.js +2 -2
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/craftTransaction.js +28 -34
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +8 -17
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +17 -28
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/estimateFees.test.js +10 -19
- package/lib-es/logic/estimateFees.test.js.map +1 -1
- package/lib-es/logic/getBalance.js +3 -14
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBalance.test.js +4 -13
- package/lib-es/logic/getBalance.test.js.map +1 -1
- package/lib-es/logic/lastBlock.js +7 -18
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +15 -5
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +84 -71
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +66 -62
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/logic/utils.js +9 -18
- package/lib-es/logic/utils.js.map +1 -1
- package/lib-es/logic/utils.test.js +9 -18
- package/lib-es/logic/utils.test.js.map +1 -1
- package/lib-es/network/index.d.ts +6 -3
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +39 -47
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/index.test.js +9 -18
- package/lib-es/network/index.test.js.map +1 -1
- package/lib-es/network/types.d.ts +5 -0
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/network/types.js.map +1 -1
- package/lib-es/signer/getAddress.js +3 -12
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/test/cli.js +5 -1
- package/lib-es/test/cli.js.map +1 -1
- package/package.json +7 -6
- package/src/api/index.integ.test.ts +12 -6
- package/src/api/index.test.ts +119 -75
- package/src/api/index.ts +62 -10
- package/src/bridge/synchronization.test.ts +31 -15
- package/src/logic/listOperations.test.ts +104 -85
- package/src/logic/listOperations.ts +47 -34
- package/src/network/index.ts +21 -8
- package/src/network/types.ts +6 -0
- package/tsconfig.json +0 -1
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Observable } from "rxjs";
|
|
11
2
|
import { encode } from "ripple-binary-codec";
|
|
12
3
|
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
@@ -14,66 +5,67 @@ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
|
14
5
|
import { craftTransaction, getNextValidSequence, removeCachedRecipientIsNew } from "../logic";
|
|
15
6
|
export const buildSignOperation = (signerContext) => ({ account, deviceId, transaction }) => new Observable(o => {
|
|
16
7
|
removeCachedRecipientIsNew(transaction.recipient);
|
|
17
|
-
function main() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
8
|
+
async function main() {
|
|
9
|
+
const { fee } = transaction;
|
|
10
|
+
if (!fee)
|
|
11
|
+
throw new FeeNotLoaded();
|
|
12
|
+
try {
|
|
13
|
+
o.next({
|
|
14
|
+
type: "device-signature-requested",
|
|
15
|
+
});
|
|
16
|
+
const nextSequenceNumber = await getNextValidSequence(account.freshAddress);
|
|
17
|
+
const signature = await signerContext(deviceId, async (signer) => {
|
|
18
|
+
const { freshAddressPath: derivationPath } = account;
|
|
19
|
+
const { publicKey } = await signer.getAddress(derivationPath);
|
|
20
|
+
const { xrplTransaction, serializedTransaction } = await craftTransaction({
|
|
21
|
+
address: account.freshAddress,
|
|
22
|
+
nextSequenceNumber,
|
|
23
|
+
}, {
|
|
24
|
+
recipient: transaction.recipient,
|
|
25
|
+
amount: BigInt(transaction.amount.toString()),
|
|
26
|
+
fee: BigInt(fee.toString()),
|
|
27
|
+
tag: transaction.tag,
|
|
28
|
+
}, publicKey);
|
|
29
|
+
const transactionSignature = await signer.signTransaction(derivationPath, serializedTransaction);
|
|
30
|
+
return encode({
|
|
31
|
+
...xrplTransaction,
|
|
32
|
+
SigningPubKey: publicKey,
|
|
33
|
+
TxnSignature: transactionSignature,
|
|
34
|
+
}).toUpperCase();
|
|
35
|
+
});
|
|
36
|
+
o.next({
|
|
37
|
+
type: "device-signature-granted",
|
|
38
|
+
});
|
|
39
|
+
const hash = "";
|
|
40
|
+
const operation = {
|
|
41
|
+
id: encodeOperationId(account.id, hash, "OUT"),
|
|
42
|
+
hash,
|
|
43
|
+
accountId: account.id,
|
|
44
|
+
type: "OUT",
|
|
45
|
+
value: transaction.amount,
|
|
46
|
+
fee,
|
|
47
|
+
blockHash: null,
|
|
48
|
+
blockHeight: null,
|
|
49
|
+
senders: [account.freshAddress],
|
|
50
|
+
recipients: [transaction.recipient],
|
|
51
|
+
date: new Date(),
|
|
52
|
+
transactionSequenceNumber: nextSequenceNumber,
|
|
53
|
+
extra: {},
|
|
54
|
+
};
|
|
55
|
+
o.next({
|
|
56
|
+
type: "signed",
|
|
57
|
+
signedOperation: {
|
|
58
|
+
operation,
|
|
59
|
+
signature,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (e instanceof Error) {
|
|
65
|
+
throw new Error(e?.data?.resultMessage);
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw new Error((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.resultMessage);
|
|
73
|
-
}
|
|
74
|
-
throw e;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
77
69
|
}
|
|
78
70
|
main().then(() => o.complete(), e => o.error(e));
|
|
79
71
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signO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QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CACZ,CAAmD,EAAE,IAAI,EAAE,aAAa,CAC1E,CAAC;YACJ,CAAC;YAED,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,IAAI,EAAE,CAAC,IAAI,CACT,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,EAClB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
11
2
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
12
3
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
13
4
|
import BigNumber from "bignumber.js";
|
|
14
5
|
import { listOperations, parseAPIValue } from "../logic";
|
|
15
6
|
import { getAccountInfo, getServerInfos } from "../network";
|
|
16
|
-
export const getAccountShape = (info) =>
|
|
7
|
+
export const getAccountShape = async (info) => {
|
|
17
8
|
const { address, initialAccount, currency, derivationMode } = info;
|
|
18
9
|
const accountId = encodeAccountId({
|
|
19
10
|
type: "js",
|
|
@@ -22,7 +13,7 @@ export const getAccountShape = (info) => __awaiter(void 0, void 0, void 0, funct
|
|
|
22
13
|
xpubOrAddress: address,
|
|
23
14
|
derivationMode,
|
|
24
15
|
});
|
|
25
|
-
const accountInfo =
|
|
16
|
+
const accountInfo = await getAccountInfo(address);
|
|
26
17
|
if (accountInfo.isNewAccount) {
|
|
27
18
|
return {
|
|
28
19
|
id: accountId,
|
|
@@ -34,14 +25,14 @@ export const getAccountShape = (info) => __awaiter(void 0, void 0, void 0, funct
|
|
|
34
25
|
operationsCount: 0,
|
|
35
26
|
};
|
|
36
27
|
}
|
|
37
|
-
const oldOperations =
|
|
28
|
+
const oldOperations = initialAccount?.operations || [];
|
|
38
29
|
const blockHeight = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
39
|
-
const serverInfo =
|
|
30
|
+
const serverInfo = await getServerInfos();
|
|
40
31
|
const ledgers = serverInfo.info.complete_ledgers.split("-");
|
|
41
32
|
const maxLedgerVersion = Number(ledgers[1]);
|
|
42
33
|
const balance = new BigNumber(accountInfo.balance);
|
|
43
|
-
const spendableBalance =
|
|
44
|
-
const newOperations =
|
|
34
|
+
const spendableBalance = await calculateSpendableBalance(accountInfo, serverInfo);
|
|
35
|
+
const newOperations = await filterOperations(accountId, address, blockHeight);
|
|
45
36
|
const operations = mergeOps(oldOperations, newOperations);
|
|
46
37
|
const shape = {
|
|
47
38
|
id: accountId,
|
|
@@ -53,36 +44,32 @@ export const getAccountShape = (info) => __awaiter(void 0, void 0, void 0, funct
|
|
|
53
44
|
operationsCount: operations.length,
|
|
54
45
|
};
|
|
55
46
|
return shape;
|
|
56
|
-
}
|
|
57
|
-
function filterOperations(accountId, address, blockHeight) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}));
|
|
75
|
-
});
|
|
47
|
+
};
|
|
48
|
+
async function filterOperations(accountId, address, blockHeight) {
|
|
49
|
+
const [operations, _] = await listOperations(address, { minHeight: blockHeight });
|
|
50
|
+
return operations.map(op => ({
|
|
51
|
+
id: encodeOperationId(accountId, op.hash, op.simpleType),
|
|
52
|
+
hash: op.hash,
|
|
53
|
+
accountId,
|
|
54
|
+
type: op.simpleType,
|
|
55
|
+
value: new BigNumber(op.value.toString()),
|
|
56
|
+
fee: new BigNumber(op.fee.toString()),
|
|
57
|
+
blockHash: op.blockHash,
|
|
58
|
+
blockHeight: op.blockHeight,
|
|
59
|
+
senders: op.senders,
|
|
60
|
+
recipients: op.recipients,
|
|
61
|
+
date: op.date,
|
|
62
|
+
transactionSequenceNumber: op.transactionSequenceNumber,
|
|
63
|
+
extra: {},
|
|
64
|
+
}));
|
|
76
65
|
}
|
|
77
|
-
function calculateSpendableBalance(account, serverInfo) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return spendableBalance;
|
|
86
|
-
});
|
|
66
|
+
async function calculateSpendableBalance(account, serverInfo) {
|
|
67
|
+
const reserveMinXRP = parseAPIValue(serverInfo.info.validated_ledger.reserve_base_xrp.toString());
|
|
68
|
+
const reservePerTrustline = parseAPIValue(serverInfo.info.validated_ledger.reserve_inc_xrp.toString());
|
|
69
|
+
const trustlines = account.ownerCount;
|
|
70
|
+
const spendableBalance = new BigNumber(account.balance)
|
|
71
|
+
.minus(reserveMinXRP)
|
|
72
|
+
.minus(reservePerTrustline.times(trustlines));
|
|
73
|
+
return spendableBalance;
|
|
87
74
|
}
|
|
88
75
|
//# sourceMappingURL=synchronization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronization.js","sourceRoot":"","sources":["../../src/bridge/synchronization.ts"],"names":[],"mappings":"
|
|
1
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ACnB,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QACzC,GAAG,EAAE,IAAI,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACrC,SAAS,EAAE,EAAE,CAAC,SAAS;QACvB,WAAW,EAAE,EAAE,CAAC,WAAW;QAC3B,OAAO,EAAE,EAAE,CAAC,OAAO;QACnB,UAAU,EAAE,EAAE,CAAC,UAAU;QACzB,IAAI,EAAE,EAAE,CAAC,IAAI;QACb,yBAAyB,EAAE,EAAE,CAAC,yBAAyB;QACvD,KAAK,EAAE,EAAE;KACV,CAAqB,CACzB,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,yBAAyB,CACtC,OAAoB,EACpB,UAA8B;IAE9B,MAAM,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClG,MAAM,mBAAmB,GAAG,aAAa,CACvC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,QAAQ,EAAE,CAC5D,CAAC;IACF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAEtC,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;SACpD,KAAK,CAAC,aAAa,CAAC;SACpB,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAEhD,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
11
2
|
import BigNumber from "bignumber.js";
|
|
12
3
|
import { getAccountShape } from "./synchronization";
|
|
@@ -37,7 +28,7 @@ describe("getAccountShape", () => {
|
|
|
37
28
|
mockGetAccountInfo.mockClear();
|
|
38
29
|
mockGetTransactions.mockClear();
|
|
39
30
|
});
|
|
40
|
-
it("returns early when account is new", () =>
|
|
31
|
+
it("returns early when account is new", async () => {
|
|
41
32
|
// Given
|
|
42
33
|
mockGetAccountInfo.mockResolvedValue({
|
|
43
34
|
isNewAccount: true,
|
|
@@ -46,7 +37,7 @@ describe("getAccountShape", () => {
|
|
|
46
37
|
sequence: 0,
|
|
47
38
|
});
|
|
48
39
|
// When
|
|
49
|
-
const account =
|
|
40
|
+
const account = await getAccountShape({
|
|
50
41
|
address: "address",
|
|
51
42
|
currency: getCryptoCurrencyById("ripple"),
|
|
52
43
|
derivationMode: "",
|
|
@@ -65,8 +56,21 @@ describe("getAccountShape", () => {
|
|
|
65
56
|
operations: [],
|
|
66
57
|
operationsCount: 0,
|
|
67
58
|
});
|
|
68
|
-
})
|
|
69
|
-
|
|
59
|
+
});
|
|
60
|
+
const someMarker = { ledger: 1, seq: 1 };
|
|
61
|
+
function mockNetworkTxs(txs) {
|
|
62
|
+
return {
|
|
63
|
+
account: "account",
|
|
64
|
+
ledger_index_max: 1,
|
|
65
|
+
ledger_index_min: 1,
|
|
66
|
+
limit: 1,
|
|
67
|
+
validated: false,
|
|
68
|
+
transactions: txs,
|
|
69
|
+
marker: someMarker,
|
|
70
|
+
error: "",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
it("convert correctly operations", async () => {
|
|
70
74
|
// Given
|
|
71
75
|
mockGetAccountInfo.mockResolvedValue({
|
|
72
76
|
isNewAccount: false,
|
|
@@ -74,7 +78,7 @@ describe("getAccountShape", () => {
|
|
|
74
78
|
ownerCount: 0,
|
|
75
79
|
sequence: 0,
|
|
76
80
|
});
|
|
77
|
-
mockGetTransactions.mockResolvedValue([
|
|
81
|
+
mockGetTransactions.mockResolvedValue(mockNetworkTxs([
|
|
78
82
|
{
|
|
79
83
|
ledger_hash: "HASH_VALUE_BLOCK",
|
|
80
84
|
hash: "HASH_VALUE",
|
|
@@ -89,9 +93,9 @@ describe("getAccountShape", () => {
|
|
|
89
93
|
Sequence: 1,
|
|
90
94
|
},
|
|
91
95
|
},
|
|
92
|
-
]);
|
|
96
|
+
]));
|
|
93
97
|
// When
|
|
94
|
-
const account =
|
|
98
|
+
const account = await getAccountShape({
|
|
95
99
|
address: "address",
|
|
96
100
|
currency: getCryptoCurrencyById("ripple"),
|
|
97
101
|
derivationMode: "",
|
|
@@ -126,6 +130,6 @@ describe("getAccountShape", () => {
|
|
|
126
130
|
},
|
|
127
131
|
],
|
|
128
132
|
});
|
|
129
|
-
})
|
|
133
|
+
});
|
|
130
134
|
});
|
|
131
135
|
//# sourceMappingURL=synchronization.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronization.test.js","sourceRoot":"","sources":["../../src/bridge/synchronization.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synchronization.test.js","sourceRoot":"","sources":["../../src/bridge/synchronization.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,KA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;oBACV,KAAK,EAAE,IAAI,SAAS,CAAC,KAAK,CAAC;oBAC3B,GAAG,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC;oBACxB,KAAK,EAAE,EAAE;iBACV;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -20,24 +20,36 @@ with fee=${!fee
|
|
|
20
20
|
export const fromTransactionRaw = (tr) => {
|
|
21
21
|
const common = fromTransactionCommonRaw(tr);
|
|
22
22
|
const { networkInfo } = tr;
|
|
23
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...common,
|
|
25
|
+
family: tr.family,
|
|
26
|
+
tag: tr.tag,
|
|
27
|
+
fee: tr.fee ? new BigNumber(tr.fee) : null,
|
|
28
|
+
feeCustomUnit: tr.feeCustomUnit,
|
|
24
29
|
// FIXME remove this field. this is not good.. we're dereferencing here. we should instead store an index (to lookup in currency.units on UI)
|
|
25
30
|
networkInfo: networkInfo && {
|
|
26
31
|
family: networkInfo.family,
|
|
27
32
|
serverFee: new BigNumber(networkInfo.serverFee),
|
|
28
33
|
baseReserve: new BigNumber(networkInfo.baseReserve),
|
|
29
|
-
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
30
36
|
};
|
|
31
37
|
export const toTransactionRaw = (t) => {
|
|
32
38
|
const common = toTransactionCommonRaw(t);
|
|
33
39
|
const { networkInfo } = t;
|
|
34
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
...common,
|
|
42
|
+
family: t.family,
|
|
43
|
+
tag: t.tag,
|
|
44
|
+
fee: t.fee ? t.fee.toString() : null,
|
|
45
|
+
feeCustomUnit: t.feeCustomUnit,
|
|
35
46
|
// FIXME remove this field. this is not good.. we're dereferencing here. we should instead store an index (to lookup in currency.units on UI)
|
|
36
47
|
networkInfo: networkInfo && {
|
|
37
48
|
family: networkInfo.family,
|
|
38
49
|
serverFee: networkInfo.serverFee.toString(),
|
|
39
50
|
baseReserve: networkInfo.baseReserve.toString(),
|
|
40
|
-
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
41
53
|
};
|
|
42
54
|
export default {
|
|
43
55
|
formatTransaction,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/bridge/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,wBAAwB,EACxB,8BAA8B,IAAI,wBAAwB,EAC1D,sBAAsB,EACtB,4BAA4B,IAAI,sBAAsB,GACvD,MAAM,oDAAoD,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAe,EAC1D,OAAgB,EACR,EAAE,CAAC;OAEX,YAAY;IACV,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE;QAC/D,QAAQ,EAAE,IAAI;QACd,eAAe,EAAE,IAAI;KACtB,CACP;KACK,SAAS;WAEZ,CAAC,GAAG;IACF,CAAC,CAAC,GAAG;IACL,CAAC,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE;QAC5D,QAAQ,EAAE,IAAI;QACd,eAAe,EAAE,IAAI;KACtB,CACP,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAEjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,E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,CAAC,QAAQ,EAAE;SAChD;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe;IACb,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,sBAAsB;IACtB,uBAAuB;CACxB,CAAC"}
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { submit } from "../network";
|
|
11
|
-
export function broadcast(signature) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return hash;
|
|
20
|
-
});
|
|
2
|
+
export async function broadcast(signature) {
|
|
3
|
+
const submittedPayment = await submit(signature);
|
|
4
|
+
if (submittedPayment.engine_result !== "tesSUCCESS" &&
|
|
5
|
+
submittedPayment.engine_result !== "terQUEUED") {
|
|
6
|
+
throw new Error(submittedPayment.engine_result_message);
|
|
7
|
+
}
|
|
8
|
+
const { hash } = submittedPayment.tx_json;
|
|
9
|
+
return hash;
|
|
21
10
|
}
|
|
22
11
|
//# sourceMappingURL=broadcast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../../src/logic/broadcast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../../src/logic/broadcast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,SAAiB;IAC/C,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAEjD,IACE,gBAAgB,CAAC,aAAa,KAAK,YAAY;QAC/C,gBAAgB,CAAC,aAAa,KAAK,WAAW,EAC9C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { broadcast } from "./broadcast";
|
|
11
2
|
const mockSubmit = jest.fn();
|
|
12
3
|
jest.mock("../network", () => ({
|
|
@@ -16,7 +7,7 @@ describe("broadcast", () => {
|
|
|
16
7
|
afterEach(() => {
|
|
17
8
|
mockSubmit.mockClear();
|
|
18
9
|
});
|
|
19
|
-
it.each(["tesSUCCESS", "terQUEUED"])("returns the transaction hash when succeesseed", (networkResult) =>
|
|
10
|
+
it.each(["tesSUCCESS", "terQUEUED"])("returns the transaction hash when succeesseed", async (networkResult) => {
|
|
20
11
|
// Given
|
|
21
12
|
const signature = "SIGNATURE";
|
|
22
13
|
mockSubmit.mockResolvedValue({
|
|
@@ -27,13 +18,13 @@ describe("broadcast", () => {
|
|
|
27
18
|
},
|
|
28
19
|
});
|
|
29
20
|
// When
|
|
30
|
-
const result =
|
|
21
|
+
const result = await broadcast(signature);
|
|
31
22
|
// Then
|
|
32
23
|
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
33
24
|
expect(mockSubmit.mock.lastCall[0]).toEqual(signature);
|
|
34
25
|
expect(result).toEqual("HASH_TX_JSON");
|
|
35
|
-
})
|
|
36
|
-
it("throws an error if 'engine_result' different from tesSUCCESS or terQUEUED", () =>
|
|
26
|
+
});
|
|
27
|
+
it("throws an error if 'engine_result' different from tesSUCCESS or terQUEUED", async () => {
|
|
37
28
|
// Given
|
|
38
29
|
const signature = "SIGNATURE";
|
|
39
30
|
const networkResultMessage = "Failed";
|
|
@@ -45,9 +36,9 @@ describe("broadcast", () => {
|
|
|
45
36
|
},
|
|
46
37
|
});
|
|
47
38
|
// When & Then
|
|
48
|
-
|
|
39
|
+
await expect(broadcast(signature)).rejects.toThrow(new Error(networkResultMessage));
|
|
49
40
|
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
50
41
|
expect(mockSubmit.mock.lastCall[0]).toEqual(signature);
|
|
51
|
-
})
|
|
42
|
+
});
|
|
52
43
|
});
|
|
53
44
|
//# sourceMappingURL=broadcast.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcast.test.js","sourceRoot":"","sources":["../../src/logic/broadcast.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broadcast.test.js","sourceRoot":"","sources":["../../src/logic/broadcast.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC7B,IAAI,CAAC,IAAI,CAAC,YAAY,E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c;QACd,MAAM,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAEpF,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/logic/combine.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { decode, encode } from "ripple-binary-codec";
|
|
2
2
|
export function combine(transaction, signature, publicKey) {
|
|
3
3
|
const xrplTransaction = decode(transaction);
|
|
4
|
-
let transactionWithSignature =
|
|
4
|
+
let transactionWithSignature = { ...xrplTransaction, TxnSignature: signature };
|
|
5
5
|
if (publicKey) {
|
|
6
|
-
transactionWithSignature =
|
|
6
|
+
transactionWithSignature = { ...transactionWithSignature, SigningPubKey: publicKey };
|
|
7
7
|
}
|
|
8
8
|
return encode(transactionWithSignature);
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combine.js","sourceRoot":"","sources":["../../src/logic/combine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQrD,MAAM,UAAU,OAAO,CAAC,WAAmB,EAAE,SAAiB,EAAE,SAAkB;IAChF,MAAM,eAAe,GAAe,MAAM,CAAC,WAAW,CAAC,CAAC;IACxD,IAAI,wBAAwB,
|
|
1
|
+
{"version":3,"file":"combine.js","sourceRoot":"","sources":["../../src/logic/combine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQrD,MAAM,UAAU,OAAO,CAAC,WAAmB,EAAE,SAAiB,EAAE,SAAkB;IAChF,MAAM,eAAe,GAAe,MAAM,CAAC,WAAW,CAAC,CAAC;IACxD,IAAI,wBAAwB,GAAmB,EAAE,GAAG,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IAE/F,IAAI,SAAS,EAAE,CAAC;QACd,wBAAwB,GAAG,EAAE,GAAG,wBAAwB,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC;IACvF,CAAC;IAED,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC;AAC1C,CAAC"}
|