@alephium/web3 0.40.0 → 0.41.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.
Files changed (58) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/api/node-provider.d.ts +2 -0
  4. package/dist/src/api/node-provider.js +12 -6
  5. package/dist/src/api/utils.d.ts +1 -1
  6. package/dist/src/block/block.d.ts +28 -0
  7. package/dist/src/block/block.js +131 -0
  8. package/dist/src/block/index.d.ts +1 -0
  9. package/dist/src/block/index.js +22 -0
  10. package/dist/src/codec/contract-output-codec.js +4 -4
  11. package/dist/src/codec/lockup-script-codec.js +2 -2
  12. package/dist/src/codec/method-codec.d.ts +3 -1
  13. package/dist/src/codec/method-codec.js +27 -2
  14. package/dist/src/codec/script-codec.d.ts +11 -6
  15. package/dist/src/codec/script-codec.js +13 -2
  16. package/dist/src/codec/transaction-codec.js +2 -2
  17. package/dist/src/codec/unlock-script-codec.d.ts +2 -2
  18. package/dist/src/codec/unsigned-tx-codec.d.ts +2 -2
  19. package/dist/src/contract/contract.d.ts +19 -10
  20. package/dist/src/contract/contract.js +103 -56
  21. package/dist/src/contract/events.d.ts +1 -2
  22. package/dist/src/contract/events.js +28 -14
  23. package/dist/src/index.d.ts +1 -0
  24. package/dist/src/index.js +1 -0
  25. package/dist/src/signer/tx-builder.js +4 -4
  26. package/dist/src/transaction/status.js +28 -4
  27. package/dist/src/utils/address.js +29 -16
  28. package/dist/src/utils/exchange.js +25 -15
  29. package/dist/src/utils/number.d.ts +1 -1
  30. package/dist/src/utils/sign.js +6 -6
  31. package/dist/src/utils/subscription.d.ts +4 -4
  32. package/dist/src/utils/subscription.js +1 -1
  33. package/package.json +3 -3
  34. package/src/api/node-provider.ts +8 -1
  35. package/src/api/utils.ts +1 -1
  36. package/src/block/block.ts +139 -0
  37. package/src/block/index.ts +19 -0
  38. package/src/codec/contract-output-codec.ts +1 -1
  39. package/src/codec/lockup-script-codec.ts +3 -3
  40. package/src/codec/method-codec.ts +41 -3
  41. package/src/codec/script-codec.ts +23 -5
  42. package/src/codec/transaction-codec.ts +1 -1
  43. package/src/codec/unlock-script-codec.ts +2 -2
  44. package/src/codec/unsigned-tx-codec.ts +2 -2
  45. package/src/contract/contract.ts +139 -78
  46. package/src/contract/events.ts +6 -18
  47. package/src/index.ts +1 -0
  48. package/src/signer/tx-builder.ts +2 -2
  49. package/src/transaction/status.ts +4 -4
  50. package/src/utils/address.ts +15 -2
  51. package/src/utils/exchange.ts +32 -10
  52. package/src/utils/number.ts +1 -1
  53. package/src/utils/sign.ts +1 -1
  54. package/src/utils/subscription.ts +4 -4
  55. package/std/fungible_token_interface.ral +1 -0
  56. package/std/nft_collection_interface.ral +1 -0
  57. package/std/nft_collection_with_royalty_interface.ral +1 -0
  58. package/std/nft_interface.ral +1 -0
@@ -1,6 +1,7 @@
1
1
  import { ApiRequestArguments, ApiRequestHandler, FungibleTokenMetaData, NFTMetaData, NFTCollectionMetaData } from './types';
2
2
  import { Api as NodeApi } from './api-alephium';
3
3
  import { HexString } from '../utils';
4
+ import * as node from '../api/api-alephium';
4
5
  interface NodeProviderApis {
5
6
  wallets: NodeApi<string>['wallets'];
6
7
  infos: NodeApi<string>['infos'];
@@ -41,4 +42,5 @@ export declare class NodeProvider implements NodeProviderApis {
41
42
  guessFollowsNFTCollectionWithRoyaltyStd: (contractId: HexString) => Promise<boolean>;
42
43
  guessStdTokenType: (tokenId: HexString) => Promise<'fungible' | 'non-fungible' | undefined>;
43
44
  }
45
+ export declare function tryGetCallResult(result: node.CallContractResult): node.CallContractSucceeded;
44
46
  export {};
@@ -17,10 +17,9 @@ 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.NodeProvider = void 0;
20
+ exports.tryGetCallResult = exports.NodeProvider = void 0;
21
21
  const types_1 = require("./types");
22
22
  const api_alephium_1 = require("./api-alephium");
23
- const contract_1 = require("../contract");
24
23
  const utils_1 = require("../utils");
25
24
  function initializeNodeApi(baseUrl, apiKey, customFetch) {
26
25
  const nodeApi = new api_alephium_1.Api({
@@ -45,7 +44,7 @@ class NodeProvider {
45
44
  const result = await this.contracts.postContractsMulticallContract({
46
45
  calls: calls
47
46
  });
48
- const callResults = result.results.map((r) => (0, contract_1.tryGetCallResult)(r));
47
+ const callResults = result.results.map((r) => tryGetCallResult(r));
49
48
  return {
50
49
  symbol: callResults[0].returns[0].value,
51
50
  name: callResults[1].returns[0].value,
@@ -61,7 +60,7 @@ class NodeProvider {
61
60
  const result = await this.contracts.postContractsMulticallContract({
62
61
  calls: calls
63
62
  });
64
- const tokenUri = (0, utils_1.hexToString)((0, contract_1.tryGetCallResult)(result.results[0]).returns[0].value);
63
+ const tokenUri = (0, utils_1.hexToString)(tryGetCallResult(result.results[0]).returns[0].value);
65
64
  const collectionIndexResult = result.results[1];
66
65
  if (collectionIndexResult.type === 'CallContractSucceeded') {
67
66
  const successfulCollectionIndexResult = result.results[1];
@@ -104,7 +103,7 @@ class NodeProvider {
104
103
  const group = (0, utils_1.groupOfAddress)(address);
105
104
  const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }));
106
105
  const result = await this.contracts.postContractsMulticallContract({ calls });
107
- const callResults = result.results.map((r) => (0, contract_1.tryGetCallResult)(r));
106
+ const callResults = result.results.map((r) => tryGetCallResult(r));
108
107
  return {
109
108
  collectionUri: (0, utils_1.hexToString)(callResults[0].returns[0].value),
110
109
  totalSupply: BigInt(callResults[1].returns[0].value)
@@ -129,7 +128,7 @@ class NodeProvider {
129
128
  }
130
129
  ]
131
130
  });
132
- const result = (0, contract_1.tryGetCallResult)(apiResult);
131
+ const result = tryGetCallResult(apiResult);
133
132
  return BigInt(result.returns[0].value);
134
133
  };
135
134
  this.guessStdInterfaceId = async (tokenId) => {
@@ -196,3 +195,10 @@ class NodeProvider {
196
195
  }
197
196
  }
198
197
  exports.NodeProvider = NodeProvider;
198
+ function tryGetCallResult(result) {
199
+ if (result.type === 'CallContractFailed') {
200
+ throw new Error(`Failed to call contract, error: ${result.error}`);
201
+ }
202
+ return result;
203
+ }
204
+ exports.tryGetCallResult = tryGetCallResult;
@@ -1,5 +1,5 @@
1
1
  import 'cross-fetch/polyfill';
2
- import { node } from '..';
2
+ import * as node from '../api/api-alephium';
3
3
  export declare function convertHttpResponse<T>(response: {
4
4
  status: number;
5
5
  data: T;
@@ -0,0 +1,28 @@
1
+ import { Subscription, SubscribeOptions } from '../utils/subscription';
2
+ import * as node from '../api/api-alephium';
3
+ import { NodeProvider } from '../api';
4
+ export type ReorgCallback = (orphanBlocks: node.BlockEntry[], newBlocks: node.BlockEntry[]) => Promise<void> | void;
5
+ export interface BlockSubscribeOptions extends SubscribeOptions<node.BlockEntry> {
6
+ reorgCallback?: ReorgCallback;
7
+ }
8
+ export declare abstract class BlockSubscriptionBase extends Subscription<node.BlockEntry> {
9
+ abstract readonly reorgCallback?: ReorgCallback;
10
+ abstract readonly fromGroup: number;
11
+ abstract readonly toGroup: number;
12
+ abstract getHashesAtHeight(height: number): Promise<string[]>;
13
+ abstract getBlockByHash(hash: string): Promise<node.BlockEntry>;
14
+ protected getParentHash(block: node.BlockEntry): string;
15
+ protected handleReorg(blockHash: string, blockHeight: number): Promise<void>;
16
+ }
17
+ export declare class BlockSubscription extends BlockSubscriptionBase {
18
+ readonly nodeProvider: NodeProvider;
19
+ readonly fromGroup: number;
20
+ readonly toGroup: number;
21
+ readonly reorgCallback?: ReorgCallback;
22
+ private currentBlockHeight;
23
+ private parentBlockHash;
24
+ constructor(options: BlockSubscribeOptions, fromGroup: number, toGroup: number, fromBlockHeight: number, nodeProvider?: NodeProvider | undefined);
25
+ getHashesAtHeight(height: number): Promise<string[]>;
26
+ getBlockByHash(hash: string): Promise<node.BlockEntry>;
27
+ polling(): Promise<void>;
28
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
29
+ }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
35
+ var __importStar = (this && this.__importStar) || function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.BlockSubscription = exports.BlockSubscriptionBase = void 0;
44
+ const subscription_1 = require("../utils/subscription");
45
+ const web3 = __importStar(require("../global"));
46
+ class BlockSubscriptionBase extends subscription_1.Subscription {
47
+ getParentHash(block) {
48
+ const index = Math.floor(block.deps.length / 2) + this.toGroup;
49
+ return block.deps[index];
50
+ }
51
+ async handleReorg(blockHash, blockHeight) {
52
+ console.info(`reorg occur, hash: ${blockHash}, height: ${blockHeight}`);
53
+ if (this.reorgCallback === undefined)
54
+ return;
55
+ const orphans = [];
56
+ const newHashes = [];
57
+ let fromHash = blockHash;
58
+ let fromHeight = blockHeight;
59
+ while (true) {
60
+ const hashes = await this.getHashesAtHeight(fromHeight);
61
+ const canonicalHash = hashes[0];
62
+ if (canonicalHash !== fromHash) {
63
+ orphans.push(fromHash);
64
+ newHashes.push(canonicalHash);
65
+ const block = await this.getBlockByHash(fromHash);
66
+ fromHash = this.getParentHash(block);
67
+ fromHeight -= 1;
68
+ }
69
+ else {
70
+ break;
71
+ }
72
+ }
73
+ const orphanBlocks = [];
74
+ for (const hash of orphans.reverse()) {
75
+ const block = await this.getBlockByHash(hash);
76
+ orphanBlocks.push(block);
77
+ }
78
+ const newBlocks = [];
79
+ for (const hash of newHashes.reverse()) {
80
+ const block = await this.getBlockByHash(hash);
81
+ newBlocks.push(block);
82
+ }
83
+ console.info(`orphan hashes: ${orphanBlocks.map((b) => b.hash)}, new hashes: ${newBlocks.map((b) => b.hash)}`);
84
+ await this.reorgCallback(orphanBlocks, newBlocks);
85
+ }
86
+ }
87
+ exports.BlockSubscriptionBase = BlockSubscriptionBase;
88
+ class BlockSubscription extends BlockSubscriptionBase {
89
+ constructor(options, fromGroup, toGroup, fromBlockHeight, nodeProvider = undefined) {
90
+ super(options);
91
+ this.nodeProvider = nodeProvider ?? web3.getCurrentNodeProvider();
92
+ this.fromGroup = fromGroup;
93
+ this.toGroup = toGroup;
94
+ this.reorgCallback = options.reorgCallback;
95
+ this.currentBlockHeight = fromBlockHeight;
96
+ this.parentBlockHash = undefined;
97
+ }
98
+ async getHashesAtHeight(height) {
99
+ const result = await this.nodeProvider.blockflow.getBlockflowHashes({
100
+ fromGroup: this.fromGroup,
101
+ toGroup: this.toGroup,
102
+ height
103
+ });
104
+ return result.headers;
105
+ }
106
+ async getBlockByHash(hash) {
107
+ return await this.nodeProvider.blockflow.getBlockflowBlocksBlockHash(hash);
108
+ }
109
+ async polling() {
110
+ try {
111
+ const chainInfo = await this.nodeProvider.blockflow.getBlockflowChainInfo({
112
+ fromGroup: this.fromGroup,
113
+ toGroup: this.toGroup
114
+ });
115
+ while (this.currentBlockHeight <= chainInfo.currentHeight) {
116
+ const hashes = await this.getHashesAtHeight(this.currentBlockHeight);
117
+ const block = await this.getBlockByHash(hashes[0]);
118
+ if (this.parentBlockHash !== undefined && this.getParentHash(block) !== this.parentBlockHash) {
119
+ await this.handleReorg(this.parentBlockHash, this.currentBlockHeight - 1);
120
+ }
121
+ await this.messageCallback(block);
122
+ this.currentBlockHeight += 1;
123
+ this.parentBlockHash = hashes[0];
124
+ }
125
+ }
126
+ catch (err) {
127
+ await this.errorCallback(err, this);
128
+ }
129
+ }
130
+ }
131
+ exports.BlockSubscription = BlockSubscription;
@@ -0,0 +1 @@
1
+ export { ReorgCallback, BlockSubscribeOptions, BlockSubscription } from './block';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.BlockSubscription = void 0;
21
+ var block_1 = require("./block");
22
+ Object.defineProperty(exports, "BlockSubscription", { enumerable: true, get: function () { return block_1.BlockSubscription; } });
@@ -23,7 +23,7 @@ const binary_parser_1 = require("binary-parser");
23
23
  const compact_int_codec_1 = require("./compact-int-codec");
24
24
  const token_codec_1 = require("./token-codec");
25
25
  const hash_1 = require("./hash");
26
- const __1 = require("..");
26
+ const utils_1 = require("../utils");
27
27
  const signed_int_codec_1 = require("./signed-int-codec");
28
28
  const lockup_script_codec_1 = require("./lockup-script-codec");
29
29
  class ContractOutputCodec {
@@ -50,9 +50,9 @@ class ContractOutputCodec {
50
50
  }
51
51
  static convertToApiContractOutput(txIdBytes, output, index) {
52
52
  const hint = (0, hash_1.createHint)(output.lockupScript.contractId);
53
- const key = (0, __1.binToHex)((0, hash_1.blakeHash)(buffer_1.Buffer.concat([txIdBytes, signed_int_codec_1.signedIntCodec.encode(index)])));
53
+ const key = (0, utils_1.binToHex)((0, hash_1.blakeHash)(buffer_1.Buffer.concat([txIdBytes, signed_int_codec_1.signedIntCodec.encode(index)])));
54
54
  const attoAlphAmount = compact_int_codec_1.compactUnsignedIntCodec.toU256(output.amount).toString();
55
- const address = __1.bs58.encode(buffer_1.Buffer.concat([buffer_1.Buffer.from([0x03]), output.lockupScript.contractId]));
55
+ const address = utils_1.bs58.encode(buffer_1.Buffer.concat([buffer_1.Buffer.from([0x03]), output.lockupScript.contractId]));
56
56
  const tokens = output.tokens.value.map((token) => {
57
57
  return {
58
58
  id: token.tokenId.toString('hex'),
@@ -63,7 +63,7 @@ class ContractOutputCodec {
63
63
  }
64
64
  static convertToOutput(apiContractOutput) {
65
65
  const amount = compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(apiContractOutput.attoAlphAmount));
66
- const lockupScript = lockup_script_codec_1.lockupScriptCodec.decode(buffer_1.Buffer.from(__1.bs58.decode(apiContractOutput.address)))
66
+ const lockupScript = lockup_script_codec_1.lockupScriptCodec.decode(buffer_1.Buffer.from(utils_1.bs58.decode(apiContractOutput.address)))
67
67
  .script;
68
68
  const tokensValue = apiContractOutput.tokens.map((token) => {
69
69
  return {
@@ -37,7 +37,7 @@ const publicKeyHashCodec = new PublicKeyHashCodec();
37
37
  const publicKeyHashesCodec = new array_codec_1.ArrayCodec(publicKeyHashCodec);
38
38
  const multiSigParser = binary_parser_1.Parser.start()
39
39
  .nest('publicKeyHashes', { type: publicKeyHashesCodec.parser })
40
- .nest('m', { type: compact_int_codec_1.compactUnsignedIntCodec.parser });
40
+ .nest('m', { type: compact_int_codec_1.compactSignedIntCodec.parser });
41
41
  class LockupScriptCodec {
42
42
  constructor() {
43
43
  this.parser = binary_parser_1.Parser.start()
@@ -59,7 +59,7 @@ class LockupScriptCodec {
59
59
  }
60
60
  else if (input.scriptType === 1) {
61
61
  result.push(...publicKeyHashesCodec.encode(input.script.publicKeyHashes.value));
62
- result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.script.m));
62
+ result.push(...compact_int_codec_1.compactSignedIntCodec.encode(input.script.m));
63
63
  }
64
64
  else if (input.scriptType === 2) {
65
65
  result.push(...input.script.scriptHash);
@@ -14,7 +14,9 @@ export interface DecodedMethod {
14
14
  }
15
15
  export interface Method {
16
16
  isPublic: boolean;
17
- assetModifier: number;
17
+ usePreapprovedAssets: boolean;
18
+ useContractAssets: boolean;
19
+ usePayToContractOnly: boolean;
18
20
  argsLength: number;
19
21
  localsLength: number;
20
22
  returnLength: number;
@@ -23,6 +23,31 @@ const binary_parser_1 = require("binary-parser");
23
23
  const array_codec_1 = require("./array-codec");
24
24
  const compact_int_codec_1 = require("./compact-int-codec");
25
25
  const instr_codec_1 = require("./instr-codec");
26
+ function decodeAssetModifier(encoded) {
27
+ const usePayToContractOnly = (encoded & 4) !== 0;
28
+ switch (encoded & 3) {
29
+ case 0:
30
+ return { usePayToContractOnly, usePreapprovedAssets: false, useContractAssets: false };
31
+ case 1:
32
+ return { usePayToContractOnly, usePreapprovedAssets: true, useContractAssets: true };
33
+ case 2:
34
+ return { usePayToContractOnly, usePreapprovedAssets: false, useContractAssets: true };
35
+ case 3:
36
+ return { usePayToContractOnly, usePreapprovedAssets: true, useContractAssets: false };
37
+ default:
38
+ throw new Error(`Invalid asset modifier: ${encoded}`);
39
+ }
40
+ }
41
+ function encodeAssetModifier(arg) {
42
+ const encoded = !arg.usePreapprovedAssets && !arg.useContractAssets
43
+ ? 0
44
+ : arg.usePreapprovedAssets && arg.useContractAssets
45
+ ? 1
46
+ : !arg.usePreapprovedAssets && arg.useContractAssets
47
+ ? 2
48
+ : 3;
49
+ return encoded | (arg.usePayToContractOnly ? 4 : 0);
50
+ }
26
51
  class MethodCodec {
27
52
  constructor() {
28
53
  this.parser = binary_parser_1.Parser.start()
@@ -55,7 +80,7 @@ class MethodCodec {
55
80
  static toMethod(decodedMethod) {
56
81
  return {
57
82
  isPublic: decodedMethod.isPublic === 1,
58
- assetModifier: decodedMethod.assetModifier,
83
+ ...decodeAssetModifier(decodedMethod.assetModifier),
59
84
  argsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.argsLength),
60
85
  localsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.localsLength),
61
86
  returnLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.returnLength),
@@ -65,7 +90,7 @@ class MethodCodec {
65
90
  static fromMethod(method) {
66
91
  return {
67
92
  isPublic: method.isPublic ? 1 : 0,
68
- assetModifier: method.assetModifier,
93
+ assetModifier: encodeAssetModifier(method),
69
94
  argsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.argsLength),
70
95
  localsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.localsLength),
71
96
  returnLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.returnLength),
@@ -2,15 +2,20 @@ import { Buffer } from 'buffer/';
2
2
  import { Parser } from 'binary-parser';
3
3
  import { DecodedArray } from './array-codec';
4
4
  import { Codec } from './codec';
5
- import { DecodedMethod } from './method-codec';
5
+ import { DecodedMethod, Method } from './method-codec';
6
6
  import { OptionCodec } from './option-codec';
7
- export interface Script {
7
+ export interface DecodedScript {
8
8
  methods: DecodedArray<DecodedMethod>;
9
9
  }
10
- export declare class ScriptCodec implements Codec<Script> {
10
+ export interface Script {
11
+ methods: Method[];
12
+ }
13
+ export declare class ScriptCodec implements Codec<DecodedScript> {
11
14
  parser: Parser;
12
- encode(input: Script): Buffer;
13
- decode(input: Buffer): Script;
15
+ encode(input: DecodedScript): Buffer;
16
+ decode(input: Buffer): DecodedScript;
17
+ decodeScript(input: Buffer): Script;
18
+ encodeScript(inputTxScript: Script): Buffer;
14
19
  }
15
20
  export declare const scriptCodec: ScriptCodec;
16
- export declare const statefulScriptCodecOpt: OptionCodec<Script>;
21
+ export declare const statefulScriptCodecOpt: OptionCodec<DecodedScript>;
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.statefulScriptCodecOpt = exports.scriptCodec = exports.ScriptCodec = void 0;
4
2
  /*
5
3
  Copyright 2018 - 2022 The Alephium Authors
6
4
  This file is part of the alephium project.
@@ -18,10 +16,13 @@ GNU Lesser General Public License for more details.
18
16
  You should have received a copy of the GNU Lesser General Public License
19
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
20
18
  */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.statefulScriptCodecOpt = exports.scriptCodec = exports.ScriptCodec = void 0;
21
21
  const buffer_1 = require("buffer/");
22
22
  const binary_parser_1 = require("binary-parser");
23
23
  const method_codec_1 = require("./method-codec");
24
24
  const option_codec_1 = require("./option-codec");
25
+ const compact_int_codec_1 = require("./compact-int-codec");
25
26
  class ScriptCodec {
26
27
  constructor() {
27
28
  this.parser = binary_parser_1.Parser.start().nest('methods', {
@@ -35,6 +36,16 @@ class ScriptCodec {
35
36
  decode(input) {
36
37
  return this.parser.parse(input);
37
38
  }
39
+ decodeScript(input) {
40
+ const decodedTxScript = this.decode(input);
41
+ const methods = decodedTxScript.methods.value.map((decodedMethod) => method_codec_1.MethodCodec.toMethod(decodedMethod));
42
+ return { methods };
43
+ }
44
+ encodeScript(inputTxScript) {
45
+ const methodLength = compact_int_codec_1.compactUnsignedIntCodec.fromU32(inputTxScript.methods.length);
46
+ const decodedMethods = inputTxScript.methods.map((method) => method_codec_1.MethodCodec.fromMethod(method));
47
+ return this.encode({ methods: { value: decodedMethods, length: methodLength } });
48
+ }
38
49
  }
39
50
  exports.ScriptCodec = ScriptCodec;
40
51
  exports.scriptCodec = new ScriptCodec();
@@ -25,7 +25,7 @@ const signature_codec_1 = require("./signature-codec");
25
25
  const contract_output_ref_codec_1 = require("./contract-output-ref-codec");
26
26
  const asset_output_codec_1 = require("./asset-output-codec");
27
27
  const contract_output_codec_1 = require("./contract-output-codec");
28
- const __1 = require("..");
28
+ const utils_1 = require("../utils");
29
29
  const output_codec_1 = require("./output-codec");
30
30
  class TransactionCodec {
31
31
  constructor() {
@@ -77,7 +77,7 @@ class TransactionCodec {
77
77
  const key = contractInput.key.toString('hex');
78
78
  return { hint, key };
79
79
  });
80
- const txIdBytes = (0, __1.hexToBinUnsafe)(txId);
80
+ const txIdBytes = (0, utils_1.hexToBinUnsafe)(txId);
81
81
  const generatedOutputs = transaction.generatedOutputs.value.map((output, index) => {
82
82
  if (output.either === 0) {
83
83
  const fixedAssetOutput = asset_output_codec_1.AssetOutputCodec.toFixedAssetOutput(txIdBytes, output.value, index);
@@ -3,7 +3,7 @@ import { Parser } from 'binary-parser';
3
3
  import { DecodedArray } from './array-codec';
4
4
  import { DecodedCompactInt } from './compact-int-codec';
5
5
  import { Codec } from './codec';
6
- import { Script } from './script-codec';
6
+ import { DecodedScript } from './script-codec';
7
7
  import { ByteString } from './bytestring-codec';
8
8
  import { LockupScript } from './lockup-script-codec';
9
9
  export interface P2PKH {
@@ -20,7 +20,7 @@ export interface Val {
20
20
  val: number | DecodedCompactInt | ByteString | LockupScript;
21
21
  }
22
22
  export interface P2SH {
23
- script: Script;
23
+ script: DecodedScript;
24
24
  params: DecodedArray<Val>;
25
25
  }
26
26
  export declare class P2SHCodec implements Codec<P2SH> {
@@ -1,7 +1,7 @@
1
1
  import { Buffer } from 'buffer/';
2
2
  import { Parser } from 'binary-parser';
3
3
  import { UnsignedTx as ApiUnsignedTx } from '../api/api-alephium';
4
- import { Script } from './script-codec';
4
+ import { DecodedScript } from './script-codec';
5
5
  import { Option } from './option-codec';
6
6
  import { DecodedCompactInt } from './compact-int-codec';
7
7
  import { Input } from './input-codec';
@@ -11,7 +11,7 @@ import { Codec } from './codec';
11
11
  export interface UnsignedTx {
12
12
  version: number;
13
13
  networkId: number;
14
- statefulScript: Option<Script>;
14
+ statefulScript: Option<DecodedScript>;
15
15
  gasAmount: DecodedCompactInt;
16
16
  gasPrice: DecodedCompactInt;
17
17
  inputs: DecodedArray<Input>;
@@ -2,10 +2,11 @@ import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
2
2
  import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address } from '../signer';
3
3
  import { Optional, HexString } from '../utils';
4
4
  import { EventSubscribeOptions, EventSubscription } from './events';
5
+ import { Method } from '../codec';
5
6
  export type FieldsSig = node.FieldsSig;
6
7
  export type MapsSig = node.MapsSig;
7
8
  export type EventSig = node.EventSig;
8
- export type FunctionSig = node.FunctionSig;
9
+ export type FunctionSig = Omit<node.FunctionSig, 'isPublic' | 'usePreapprovedAssets' | 'useAssetsInContract'>;
9
10
  export type Fields = NamedVals;
10
11
  export type Arguments = NamedVals;
11
12
  export type Constant = node.Constant;
@@ -61,7 +62,8 @@ export declare class ProjectArtifact {
61
62
  constructor(fullNodeVersion: string, compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>);
62
63
  static isCodeChanged(current: ProjectArtifact, previous: ProjectArtifact): boolean;
63
64
  saveToFile(rootPath: string): Promise<void>;
64
- needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[], fullNodeVersion: string): boolean;
65
+ getChangedSources(sourceInfos: SourceInfo[]): SourceInfo[];
66
+ needToReCompile(compilerOptions: node.CompilerOptions, fullNodeVersion: string): boolean;
65
67
  static from(rootPath: string): Promise<ProjectArtifact | undefined>;
66
68
  }
67
69
  export declare class Struct {
@@ -98,6 +100,7 @@ export declare class Project {
98
100
  private static loadStructs;
99
101
  private saveStructsToFile;
100
102
  private saveArtifactsToFile;
103
+ private saveProjectArtifact;
101
104
  contractByCodeHash(codeHash: string): Contract;
102
105
  private static getCompileResult;
103
106
  private static compile;
@@ -108,7 +111,7 @@ export declare class Project {
108
111
  private static loadSourceFiles;
109
112
  static readonly DEFAULT_CONTRACTS_DIR = "contracts";
110
113
  static readonly DEFAULT_ARTIFACTS_DIR = "artifacts";
111
- static build(compilerOptionsPartial?: Partial<CompilerOptions>, projectRootDir?: string, contractsRootDir?: string, artifactsRootDir?: string, defaultFullNodeVersion?: string | undefined): Promise<void>;
114
+ static build(compilerOptionsPartial?: Partial<CompilerOptions>, projectRootDir?: string, contractsRootDir?: string, artifactsRootDir?: string, defaultFullNodeVersion?: string | undefined, skipSaveArtifacts?: boolean): Promise<void>;
112
115
  }
113
116
  export declare abstract class Artifact {
114
117
  readonly version: string;
@@ -116,9 +119,6 @@ export declare abstract class Artifact {
116
119
  readonly functions: FunctionSig[];
117
120
  constructor(version: string, name: string, functions: FunctionSig[]);
118
121
  abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
119
- publicFunctions(): string[];
120
- usingPreapprovedAssetsFunctions(): string[];
121
- usingAssetsInContractFunctions(): string[];
122
122
  isDevnet(signer: SignerProvider): Promise<boolean>;
123
123
  }
124
124
  export declare class Contract extends Artifact {
@@ -134,7 +134,11 @@ export declare class Contract extends Artifact {
134
134
  readonly stdInterfaceId?: HexString;
135
135
  readonly bytecodeDebug: string;
136
136
  readonly codeHashDebug: string;
137
+ readonly decodedMethods: Method[];
137
138
  constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], structs: Struct[], mapsSig?: MapsSig, stdInterfaceId?: HexString);
139
+ publicFunctions(): FunctionSig[];
140
+ usingPreapprovedAssetsFunctions(): FunctionSig[];
141
+ usingAssetsInContractFunctions(): FunctionSig[];
138
142
  static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
139
143
  static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
140
144
  static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
@@ -323,13 +327,19 @@ export declare function addStdIdToFields<F extends Fields>(contract: Contract, f
323
327
  export declare function testMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>>(factory: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A, M>, 'testArgs' | 'initialFields'>): Promise<TestContractResult<R, M>>;
324
328
  export declare class RalphMap<K extends Val, V extends Val> {
325
329
  private readonly parentContract;
326
- private readonly parentInstance;
330
+ private readonly parentContractId;
327
331
  private readonly mapName;
328
- constructor(parentContract: Contract, parentInstance: ContractInstance, mapName: string);
332
+ private readonly groupIndex;
333
+ constructor(parentContract: Contract, parentContractId: HexString, mapName: string);
329
334
  get(key: K): Promise<V | undefined>;
330
335
  contains(key: K): Promise<boolean>;
336
+ toJSON(): {
337
+ parentContractId: string;
338
+ mapName: string;
339
+ groupIndex: number;
340
+ };
331
341
  }
332
- export declare function getMapItem<R extends Val>(parentContract: Contract, parentInstance: ContractInstance, mapName: string, key: Val): Promise<R | undefined>;
342
+ export declare function getMapItem<R extends Val>(parentContract: Contract, parentContractId: HexString, groupIndex: number, mapName: string, key: Val): Promise<R | undefined>;
333
343
  export declare abstract class ContractInstance {
334
344
  readonly address: Address;
335
345
  readonly contractId: string;
@@ -347,5 +357,4 @@ export declare function multicallMethods<I extends ContractInstance, F extends F
347
357
  export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
348
358
  export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
349
359
  export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
350
- export declare function tryGetCallResult(result: node.CallContractResult): node.CallContractSucceeded;
351
360
  export {};