@alephium/web3 1.8.5 → 1.10.0
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +25 -6
- package/dist/src/api/api-alephium.js +33 -4
- package/dist/src/api/api-explorer.d.ts +810 -819
- package/dist/src/api/api-explorer.js +350 -360
- package/dist/src/codec/instr-codec.d.ts +2 -0
- package/dist/src/codec/instr-codec.js +54 -1
- package/dist/src/codec/unlock-script-codec.d.ts +1 -0
- package/dist/src/codec/unlock-script-codec.js +2 -1
- package/dist/src/constants.d.ts +4 -0
- package/dist/src/constants.js +5 -1
- package/dist/src/contract/contract.d.ts +5 -1
- package/dist/src/contract/contract.js +44 -8
- package/dist/src/contract/dapp-tx-builder.d.ts +26 -0
- package/dist/src/contract/dapp-tx-builder.js +187 -0
- package/dist/src/contract/events.d.ts +1 -0
- package/dist/src/contract/events.js +14 -3
- package/dist/src/contract/index.d.ts +1 -0
- package/dist/src/contract/index.js +3 -0
- package/dist/src/contract/ralph.js +2 -34
- package/dist/src/exchange/exchange.d.ts +13 -2
- package/dist/src/exchange/exchange.js +52 -14
- package/dist/src/exchange/index.d.ts +1 -1
- package/dist/src/exchange/index.js +3 -2
- package/dist/src/signer/types.d.ts +1 -0
- package/package.json +5 -5
- package/src/api/api-alephium.ts +49 -9
- package/src/api/api-explorer.ts +990 -1000
- package/src/codec/instr-codec.ts +56 -1
- package/src/codec/unlock-script-codec.ts +2 -0
- package/src/constants.ts +4 -0
- package/src/contract/contract.ts +46 -7
- package/src/contract/dapp-tx-builder.ts +209 -0
- package/src/contract/events.ts +15 -3
- package/src/contract/index.ts +1 -0
- package/src/contract/ralph.ts +4 -49
- package/src/exchange/exchange.ts +69 -17
- package/src/exchange/index.ts +10 -1
- package/src/signer/tx-builder.ts +2 -2
- package/src/signer/types.ts +1 -0
|
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
20
|
+
exports.isTransferTx = exports.getAddressFromUnlockScript = exports.getSenderAddress = exports.getDepositInfo = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
|
|
21
21
|
const address_1 = require("../address");
|
|
22
22
|
const utils_1 = require("../utils");
|
|
23
23
|
const unlock_script_codec_1 = require("../codec/unlock-script-codec");
|
|
@@ -41,19 +41,9 @@ function isALPHTransferTx(tx) {
|
|
|
41
41
|
}
|
|
42
42
|
exports.isALPHTransferTx = isALPHTransferTx;
|
|
43
43
|
function getALPHDepositInfo(tx) {
|
|
44
|
-
if (!isALPHTransferTx(tx))
|
|
44
|
+
if (!isALPHTransferTx(tx))
|
|
45
45
|
return [];
|
|
46
|
-
|
|
47
|
-
const inputAddresses = [];
|
|
48
|
-
for (const input of tx.unsigned.inputs) {
|
|
49
|
-
try {
|
|
50
|
-
const address = getAddressFromUnlockScript(input.unlockScript);
|
|
51
|
-
if (!inputAddresses.includes(address)) {
|
|
52
|
-
inputAddresses.push(address);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (_) { }
|
|
56
|
-
}
|
|
46
|
+
const inputAddresses = getInputAddresses(tx);
|
|
57
47
|
const result = new Map();
|
|
58
48
|
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
59
49
|
if (!inputAddresses.includes(o.address)) {
|
|
@@ -69,7 +59,54 @@ function getALPHDepositInfo(tx) {
|
|
|
69
59
|
return Array.from(result.entries()).map(([key, value]) => ({ targetAddress: key, depositAmount: value }));
|
|
70
60
|
}
|
|
71
61
|
exports.getALPHDepositInfo = getALPHDepositInfo;
|
|
72
|
-
|
|
62
|
+
function getInputAddresses(tx) {
|
|
63
|
+
const inputAddresses = [];
|
|
64
|
+
for (const input of tx.unsigned.inputs) {
|
|
65
|
+
try {
|
|
66
|
+
if (input.unlockScript === (0, utils_1.binToHex)(unlock_script_codec_1.encodedSameAsPrevious))
|
|
67
|
+
continue;
|
|
68
|
+
const address = getAddressFromUnlockScript(input.unlockScript);
|
|
69
|
+
if (!inputAddresses.includes(address)) {
|
|
70
|
+
inputAddresses.push(address);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new error_1.TraceableError(`Failed to decode address from unlock script`, error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return inputAddresses;
|
|
78
|
+
}
|
|
79
|
+
function getDepositInfo(tx) {
|
|
80
|
+
if (!isTransferTx(tx))
|
|
81
|
+
return { alph: [], tokens: [] };
|
|
82
|
+
const inputAddresses = getInputAddresses(tx);
|
|
83
|
+
const alphDepositInfos = new Map();
|
|
84
|
+
const tokenDepositInfos = new Map();
|
|
85
|
+
tx.unsigned.fixedOutputs.forEach((o) => {
|
|
86
|
+
if (!inputAddresses.includes(o.address)) {
|
|
87
|
+
const alphAmount = alphDepositInfos.get(o.address) ?? 0n;
|
|
88
|
+
alphDepositInfos.set(o.address, alphAmount + BigInt(o.attoAlphAmount));
|
|
89
|
+
o.tokens.forEach((token) => {
|
|
90
|
+
const depositPerToken = tokenDepositInfos.get(token.id) ?? new Map();
|
|
91
|
+
const currentAmount = depositPerToken.get(o.address) ?? 0n;
|
|
92
|
+
depositPerToken.set(o.address, currentAmount + BigInt(token.amount));
|
|
93
|
+
tokenDepositInfos.set(token.id, depositPerToken);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
alph: Array.from(alphDepositInfos.entries()).map(([key, value]) => ({ targetAddress: key, depositAmount: value })),
|
|
99
|
+
tokens: Array.from(tokenDepositInfos.entries()).flatMap(([tokenId, depositPerToken]) => {
|
|
100
|
+
return Array.from(depositPerToken.entries()).map(([targetAddress, depositAmount]) => ({
|
|
101
|
+
tokenId,
|
|
102
|
+
targetAddress,
|
|
103
|
+
depositAmount
|
|
104
|
+
}));
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.getDepositInfo = getDepositInfo;
|
|
109
|
+
// we assume that the tx is a simple transfer tx, i.e. isALPHTransferTx(tx) || isTokenTransferTx(tx)
|
|
73
110
|
function getSenderAddress(tx) {
|
|
74
111
|
return getAddressFromUnlockScript(tx.unsigned.inputs[0].unlockScript);
|
|
75
112
|
}
|
|
@@ -124,3 +161,4 @@ function isTransferTx(tx) {
|
|
|
124
161
|
}
|
|
125
162
|
return true;
|
|
126
163
|
}
|
|
164
|
+
exports.isTransferTx = isTransferTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { validateExchangeAddress,
|
|
1
|
+
export { validateExchangeAddress, getSenderAddress, isALPHTransferTx, getALPHDepositInfo, BaseDepositInfo, TokenDepositInfo, DepositInfo, getDepositInfo } from './exchange';
|
|
@@ -17,9 +17,10 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.getDepositInfo = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.getSenderAddress = exports.validateExchangeAddress = void 0;
|
|
21
21
|
var exchange_1 = require("./exchange");
|
|
22
22
|
Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
|
|
23
|
-
Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
|
|
24
23
|
Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
|
|
24
|
+
Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
|
|
25
25
|
Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
|
|
26
|
+
Object.defineProperty(exports, "getDepositInfo", { enumerable: true, get: function () { return exchange_1.getDepositInfo; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Alephium dev <dev@alephium.org>",
|
|
35
35
|
"config": {
|
|
36
|
-
"alephium_version": "3.
|
|
37
|
-
"explorer_backend_version": "2.2
|
|
36
|
+
"alephium_version": "3.10.0",
|
|
37
|
+
"explorer_backend_version": "2.3.2"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
|
40
40
|
"dependencies": {
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"bn.js": "5.2.1",
|
|
46
46
|
"cross-fetch": "^3.1.5",
|
|
47
47
|
"crypto-browserify": "^3.12.0",
|
|
48
|
-
"elliptic": "6.
|
|
48
|
+
"elliptic": "6.6.0",
|
|
49
49
|
"eventemitter3": "^4.0.7",
|
|
50
50
|
"path-browserify": "^1.0.1",
|
|
51
51
|
"stream-browserify": "^3.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/eslint-parser": "^7.21.3",
|
|
55
|
-
"@types/elliptic": "^6.4.
|
|
55
|
+
"@types/elliptic": "^6.4.18",
|
|
56
56
|
"@types/find-up": "^2.1.1",
|
|
57
57
|
"@types/fs-extra": "^9.0.13",
|
|
58
58
|
"@types/jest": "^27.5.2",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -308,6 +308,7 @@ export interface BuildExecuteScriptTxResult {
|
|
|
308
308
|
gasPrice: string
|
|
309
309
|
/** @format 32-byte-hash */
|
|
310
310
|
txId: string
|
|
311
|
+
simulatedOutputs: Output[]
|
|
311
312
|
}
|
|
312
313
|
|
|
313
314
|
/** BuildInfo */
|
|
@@ -366,6 +367,8 @@ export interface BuildSweepAddressTransactions {
|
|
|
366
367
|
gasPrice?: string
|
|
367
368
|
/** @format block-hash */
|
|
368
369
|
targetBlockHash?: string
|
|
370
|
+
/** @format int32 */
|
|
371
|
+
utxosLimit?: number
|
|
369
372
|
}
|
|
370
373
|
|
|
371
374
|
/** BuildSweepAddressTransactionsResult */
|
|
@@ -1406,11 +1409,6 @@ export interface WalletCreationResult {
|
|
|
1406
1409
|
mnemonic: string
|
|
1407
1410
|
}
|
|
1408
1411
|
|
|
1409
|
-
/** WalletDeletion */
|
|
1410
|
-
export interface WalletDeletion {
|
|
1411
|
-
password: string
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
1412
|
/** WalletRestore */
|
|
1415
1413
|
export interface WalletRestore {
|
|
1416
1414
|
password: string
|
|
@@ -1651,7 +1649,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1651
1649
|
|
|
1652
1650
|
/**
|
|
1653
1651
|
* @title Alephium API
|
|
1654
|
-
* @version 3.
|
|
1652
|
+
* @version 3.10.0
|
|
1655
1653
|
* @baseUrl ../
|
|
1656
1654
|
*/
|
|
1657
1655
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1738,12 +1736,17 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1738
1736
|
* @summary Delete your wallet file (can be recovered with your mnemonic)
|
|
1739
1737
|
* @request DELETE:/wallets/{wallet_name}
|
|
1740
1738
|
*/
|
|
1741
|
-
deleteWalletsWalletName: (
|
|
1739
|
+
deleteWalletsWalletName: (
|
|
1740
|
+
walletName: string,
|
|
1741
|
+
query: {
|
|
1742
|
+
password: string
|
|
1743
|
+
},
|
|
1744
|
+
params: RequestParams = {}
|
|
1745
|
+
) =>
|
|
1742
1746
|
this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1743
1747
|
path: `/wallets/${walletName}`,
|
|
1744
1748
|
method: 'DELETE',
|
|
1745
|
-
|
|
1746
|
-
type: ContentType.Json,
|
|
1749
|
+
query: query,
|
|
1747
1750
|
...params
|
|
1748
1751
|
}).then(convertHttpResponse),
|
|
1749
1752
|
|
|
@@ -2593,6 +2596,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2593
2596
|
...params
|
|
2594
2597
|
}).then(convertHttpResponse),
|
|
2595
2598
|
|
|
2599
|
+
/**
|
|
2600
|
+
* No description
|
|
2601
|
+
*
|
|
2602
|
+
* @tags Transactions
|
|
2603
|
+
* @name PostTransactionsBuildTransferFromOneToManyGroups
|
|
2604
|
+
* @summary Build unsigned transfer transactions from an address of one group to addresses of many groups. Each target group requires a dedicated transaction or more in case large number of outputs needed to be split.
|
|
2605
|
+
* @request POST:/transactions/build-transfer-from-one-to-many-groups
|
|
2606
|
+
*/
|
|
2607
|
+
postTransactionsBuildTransferFromOneToManyGroups: (data: BuildTransferTx, params: RequestParams = {}) =>
|
|
2608
|
+
this.request<
|
|
2609
|
+
BuildTransferTxResult[],
|
|
2610
|
+
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2611
|
+
>({
|
|
2612
|
+
path: `/transactions/build-transfer-from-one-to-many-groups`,
|
|
2613
|
+
method: 'POST',
|
|
2614
|
+
body: data,
|
|
2615
|
+
type: ContentType.Json,
|
|
2616
|
+
format: 'json',
|
|
2617
|
+
...params
|
|
2618
|
+
}).then(convertHttpResponse),
|
|
2619
|
+
|
|
2596
2620
|
/**
|
|
2597
2621
|
* No description
|
|
2598
2622
|
*
|
|
@@ -3019,6 +3043,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
3019
3043
|
...params
|
|
3020
3044
|
}).then(convertHttpResponse),
|
|
3021
3045
|
|
|
3046
|
+
/**
|
|
3047
|
+
* No description
|
|
3048
|
+
*
|
|
3049
|
+
* @tags Contracts
|
|
3050
|
+
* @name GetContractsCodehashCode
|
|
3051
|
+
* @summary Get contract code by code hash
|
|
3052
|
+
* @request GET:/contracts/{codeHash}/code
|
|
3053
|
+
*/
|
|
3054
|
+
getContractsCodehashCode: (codeHash: string, params: RequestParams = {}) =>
|
|
3055
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
3056
|
+
path: `/contracts/${codeHash}/code`,
|
|
3057
|
+
method: 'GET',
|
|
3058
|
+
format: 'json',
|
|
3059
|
+
...params
|
|
3060
|
+
}).then(convertHttpResponse),
|
|
3061
|
+
|
|
3022
3062
|
/**
|
|
3023
3063
|
* No description
|
|
3024
3064
|
*
|