@alephium/web3 1.5.2 → 1.7.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 +86 -1
- package/dist/src/api/api-alephium.js +88 -1
- package/dist/src/contract/contract.d.ts +11 -4
- package/dist/src/contract/contract.js +44 -10
- package/package.json +2 -2
- package/src/api/api-alephium.ts +145 -1
- package/src/contract/contract.ts +61 -18
|
@@ -790,6 +790,16 @@ export interface Project {
|
|
|
790
790
|
code: string;
|
|
791
791
|
compilerOptions?: CompilerOptions;
|
|
792
792
|
}
|
|
793
|
+
/** RawBlock */
|
|
794
|
+
export interface RawBlock {
|
|
795
|
+
/** @format hex-string */
|
|
796
|
+
value: string;
|
|
797
|
+
}
|
|
798
|
+
/** RawTransaction */
|
|
799
|
+
export interface RawTransaction {
|
|
800
|
+
/** @format hex-string */
|
|
801
|
+
value: string;
|
|
802
|
+
}
|
|
793
803
|
/** Reachable */
|
|
794
804
|
export interface Reachable {
|
|
795
805
|
peers: string[];
|
|
@@ -853,6 +863,12 @@ export interface StructSig {
|
|
|
853
863
|
fieldTypes: string[];
|
|
854
864
|
isMutable: boolean[];
|
|
855
865
|
}
|
|
866
|
+
/** SubContracts */
|
|
867
|
+
export interface SubContracts {
|
|
868
|
+
subContracts: string[];
|
|
869
|
+
/** @format int32 */
|
|
870
|
+
nextStart: number;
|
|
871
|
+
}
|
|
856
872
|
/** SubmitMultisig */
|
|
857
873
|
export interface SubmitMultisig {
|
|
858
874
|
unsignedTx: string;
|
|
@@ -1189,7 +1205,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1189
1205
|
}
|
|
1190
1206
|
/**
|
|
1191
1207
|
* @title Alephium API
|
|
1192
|
-
* @version 3.
|
|
1208
|
+
* @version 3.6.2
|
|
1193
1209
|
* @baseUrl ../
|
|
1194
1210
|
*/
|
|
1195
1211
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1624,6 +1640,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1624
1640
|
* @request GET:/blockflow/headers/{block_hash}
|
|
1625
1641
|
*/
|
|
1626
1642
|
getBlockflowHeadersBlockHash: (blockHash: string, params?: RequestParams) => Promise<BlockHeaderEntry>;
|
|
1643
|
+
/**
|
|
1644
|
+
* No description
|
|
1645
|
+
*
|
|
1646
|
+
* @tags Blockflow
|
|
1647
|
+
* @name GetBlockflowRawBlocksBlockHash
|
|
1648
|
+
* @summary Get raw block in hex format
|
|
1649
|
+
* @request GET:/blockflow/raw-blocks/{block_hash}
|
|
1650
|
+
*/
|
|
1651
|
+
getBlockflowRawBlocksBlockHash: (blockHash: string, params?: RequestParams) => Promise<RawBlock>;
|
|
1627
1652
|
};
|
|
1628
1653
|
addresses: {
|
|
1629
1654
|
/**
|
|
@@ -1716,6 +1741,20 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1716
1741
|
/** @format int32 */
|
|
1717
1742
|
toGroup?: number;
|
|
1718
1743
|
}, params?: RequestParams) => Promise<Transaction>;
|
|
1744
|
+
/**
|
|
1745
|
+
* No description
|
|
1746
|
+
*
|
|
1747
|
+
* @tags Transactions
|
|
1748
|
+
* @name GetTransactionsRawTxid
|
|
1749
|
+
* @summary Get raw transaction in hex format
|
|
1750
|
+
* @request GET:/transactions/raw/{txId}
|
|
1751
|
+
*/
|
|
1752
|
+
getTransactionsRawTxid: (txId: string, query?: {
|
|
1753
|
+
/** @format int32 */
|
|
1754
|
+
fromGroup?: number;
|
|
1755
|
+
/** @format int32 */
|
|
1756
|
+
toGroup?: number;
|
|
1757
|
+
}, params?: RequestParams) => Promise<RawTransaction>;
|
|
1719
1758
|
/**
|
|
1720
1759
|
* No description
|
|
1721
1760
|
*
|
|
@@ -1732,6 +1771,20 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1732
1771
|
/** @format int32 */
|
|
1733
1772
|
toGroup?: number;
|
|
1734
1773
|
}, params?: RequestParams) => Promise<Confirmed | MemPooled | TxNotFound>;
|
|
1774
|
+
/**
|
|
1775
|
+
* No description
|
|
1776
|
+
*
|
|
1777
|
+
* @tags Transactions
|
|
1778
|
+
* @name GetTransactionsTxIdFromOutputref
|
|
1779
|
+
* @summary Get transaction id from transaction output ref
|
|
1780
|
+
* @request GET:/transactions/tx-id-from-outputref
|
|
1781
|
+
*/
|
|
1782
|
+
getTransactionsTxIdFromOutputref: (query: {
|
|
1783
|
+
/** @format int32 */
|
|
1784
|
+
hint: number;
|
|
1785
|
+
/** @format 32-byte-hash */
|
|
1786
|
+
key: string;
|
|
1787
|
+
}, params?: RequestParams) => Promise<string>;
|
|
1735
1788
|
};
|
|
1736
1789
|
mempool: {
|
|
1737
1790
|
/**
|
|
@@ -1856,6 +1909,38 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1856
1909
|
* @request POST:/contracts/multicall-contract
|
|
1857
1910
|
*/
|
|
1858
1911
|
postContractsMulticallContract: (data: MultipleCallContract, params?: RequestParams) => Promise<MultipleCallContractResult>;
|
|
1912
|
+
/**
|
|
1913
|
+
* No description
|
|
1914
|
+
*
|
|
1915
|
+
* @tags Contracts
|
|
1916
|
+
* @name GetContractsAddressParent
|
|
1917
|
+
* @summary Get parent contract address
|
|
1918
|
+
* @request GET:/contracts/{address}/parent
|
|
1919
|
+
*/
|
|
1920
|
+
getContractsAddressParent: (address: string, params?: RequestParams) => Promise<string>;
|
|
1921
|
+
/**
|
|
1922
|
+
* No description
|
|
1923
|
+
*
|
|
1924
|
+
* @tags Contracts
|
|
1925
|
+
* @name GetContractsAddressSubContracts
|
|
1926
|
+
* @summary Get sub-contract addresses
|
|
1927
|
+
* @request GET:/contracts/{address}/sub-contracts
|
|
1928
|
+
*/
|
|
1929
|
+
getContractsAddressSubContracts: (address: string, query: {
|
|
1930
|
+
/** @format int32 */
|
|
1931
|
+
start: number;
|
|
1932
|
+
/** @format int32 */
|
|
1933
|
+
limit?: number;
|
|
1934
|
+
}, params?: RequestParams) => Promise<SubContracts>;
|
|
1935
|
+
/**
|
|
1936
|
+
* No description
|
|
1937
|
+
*
|
|
1938
|
+
* @tags Contracts
|
|
1939
|
+
* @name GetContractsAddressSubContractsCurrentCount
|
|
1940
|
+
* @summary Get current value of the sub-contracts counter for a contract
|
|
1941
|
+
* @request GET:/contracts/{address}/sub-contracts/current-count
|
|
1942
|
+
*/
|
|
1943
|
+
getContractsAddressSubContractsCurrentCount: (address: string, params?: RequestParams) => Promise<number>;
|
|
1859
1944
|
/**
|
|
1860
1945
|
* No description
|
|
1861
1946
|
*
|
|
@@ -151,7 +151,7 @@ class HttpClient {
|
|
|
151
151
|
exports.HttpClient = HttpClient;
|
|
152
152
|
/**
|
|
153
153
|
* @title Alephium API
|
|
154
|
-
* @version 3.
|
|
154
|
+
* @version 3.6.2
|
|
155
155
|
* @baseUrl ../
|
|
156
156
|
*/
|
|
157
157
|
class Api extends HttpClient {
|
|
@@ -761,6 +761,20 @@ class Api extends HttpClient {
|
|
|
761
761
|
method: 'GET',
|
|
762
762
|
format: 'json',
|
|
763
763
|
...params
|
|
764
|
+
}).then(utils_1.convertHttpResponse),
|
|
765
|
+
/**
|
|
766
|
+
* No description
|
|
767
|
+
*
|
|
768
|
+
* @tags Blockflow
|
|
769
|
+
* @name GetBlockflowRawBlocksBlockHash
|
|
770
|
+
* @summary Get raw block in hex format
|
|
771
|
+
* @request GET:/blockflow/raw-blocks/{block_hash}
|
|
772
|
+
*/
|
|
773
|
+
getBlockflowRawBlocksBlockHash: (blockHash, params = {}) => this.request({
|
|
774
|
+
path: `/blockflow/raw-blocks/${blockHash}`,
|
|
775
|
+
method: 'GET',
|
|
776
|
+
format: 'json',
|
|
777
|
+
...params
|
|
764
778
|
}).then(utils_1.convertHttpResponse)
|
|
765
779
|
};
|
|
766
780
|
this.addresses = {
|
|
@@ -904,6 +918,21 @@ class Api extends HttpClient {
|
|
|
904
918
|
format: 'json',
|
|
905
919
|
...params
|
|
906
920
|
}).then(utils_1.convertHttpResponse),
|
|
921
|
+
/**
|
|
922
|
+
* No description
|
|
923
|
+
*
|
|
924
|
+
* @tags Transactions
|
|
925
|
+
* @name GetTransactionsRawTxid
|
|
926
|
+
* @summary Get raw transaction in hex format
|
|
927
|
+
* @request GET:/transactions/raw/{txId}
|
|
928
|
+
*/
|
|
929
|
+
getTransactionsRawTxid: (txId, query, params = {}) => this.request({
|
|
930
|
+
path: `/transactions/raw/${txId}`,
|
|
931
|
+
method: 'GET',
|
|
932
|
+
query: query,
|
|
933
|
+
format: 'json',
|
|
934
|
+
...params
|
|
935
|
+
}).then(utils_1.convertHttpResponse),
|
|
907
936
|
/**
|
|
908
937
|
* No description
|
|
909
938
|
*
|
|
@@ -918,6 +947,21 @@ class Api extends HttpClient {
|
|
|
918
947
|
query: query,
|
|
919
948
|
format: 'json',
|
|
920
949
|
...params
|
|
950
|
+
}).then(utils_1.convertHttpResponse),
|
|
951
|
+
/**
|
|
952
|
+
* No description
|
|
953
|
+
*
|
|
954
|
+
* @tags Transactions
|
|
955
|
+
* @name GetTransactionsTxIdFromOutputref
|
|
956
|
+
* @summary Get transaction id from transaction output ref
|
|
957
|
+
* @request GET:/transactions/tx-id-from-outputref
|
|
958
|
+
*/
|
|
959
|
+
getTransactionsTxIdFromOutputref: (query, params = {}) => this.request({
|
|
960
|
+
path: `/transactions/tx-id-from-outputref`,
|
|
961
|
+
method: 'GET',
|
|
962
|
+
query: query,
|
|
963
|
+
format: 'json',
|
|
964
|
+
...params
|
|
921
965
|
}).then(utils_1.convertHttpResponse)
|
|
922
966
|
};
|
|
923
967
|
this.mempool = {
|
|
@@ -1119,6 +1163,49 @@ class Api extends HttpClient {
|
|
|
1119
1163
|
format: 'json',
|
|
1120
1164
|
...params
|
|
1121
1165
|
}).then(utils_1.convertHttpResponse),
|
|
1166
|
+
/**
|
|
1167
|
+
* No description
|
|
1168
|
+
*
|
|
1169
|
+
* @tags Contracts
|
|
1170
|
+
* @name GetContractsAddressParent
|
|
1171
|
+
* @summary Get parent contract address
|
|
1172
|
+
* @request GET:/contracts/{address}/parent
|
|
1173
|
+
*/
|
|
1174
|
+
getContractsAddressParent: (address, params = {}) => this.request({
|
|
1175
|
+
path: `/contracts/${address}/parent`,
|
|
1176
|
+
method: 'GET',
|
|
1177
|
+
format: 'json',
|
|
1178
|
+
...params
|
|
1179
|
+
}).then(utils_1.convertHttpResponse),
|
|
1180
|
+
/**
|
|
1181
|
+
* No description
|
|
1182
|
+
*
|
|
1183
|
+
* @tags Contracts
|
|
1184
|
+
* @name GetContractsAddressSubContracts
|
|
1185
|
+
* @summary Get sub-contract addresses
|
|
1186
|
+
* @request GET:/contracts/{address}/sub-contracts
|
|
1187
|
+
*/
|
|
1188
|
+
getContractsAddressSubContracts: (address, query, params = {}) => this.request({
|
|
1189
|
+
path: `/contracts/${address}/sub-contracts`,
|
|
1190
|
+
method: 'GET',
|
|
1191
|
+
query: query,
|
|
1192
|
+
format: 'json',
|
|
1193
|
+
...params
|
|
1194
|
+
}).then(utils_1.convertHttpResponse),
|
|
1195
|
+
/**
|
|
1196
|
+
* No description
|
|
1197
|
+
*
|
|
1198
|
+
* @tags Contracts
|
|
1199
|
+
* @name GetContractsAddressSubContractsCurrentCount
|
|
1200
|
+
* @summary Get current value of the sub-contracts counter for a contract
|
|
1201
|
+
* @request GET:/contracts/{address}/sub-contracts/current-count
|
|
1202
|
+
*/
|
|
1203
|
+
getContractsAddressSubContractsCurrentCount: (address, params = {}) => this.request({
|
|
1204
|
+
path: `/contracts/${address}/sub-contracts/current-count`,
|
|
1205
|
+
method: 'GET',
|
|
1206
|
+
format: 'json',
|
|
1207
|
+
...params
|
|
1208
|
+
}).then(utils_1.convertHttpResponse),
|
|
1122
1209
|
/**
|
|
1123
1210
|
* No description
|
|
1124
1211
|
*
|
|
@@ -2,7 +2,7 @@ import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
|
|
|
2
2
|
import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address, SignExecuteScriptTxResult } from '../signer';
|
|
3
3
|
import { Optional, HexString } from '../utils';
|
|
4
4
|
import { EventSubscribeOptions, EventSubscription } from './events';
|
|
5
|
-
import { Method } from '../codec';
|
|
5
|
+
import { contract, Method } from '../codec';
|
|
6
6
|
export type FieldsSig = node.FieldsSig;
|
|
7
7
|
export type MapsSig = node.MapsSig;
|
|
8
8
|
export type EventSig = node.EventSig;
|
|
@@ -32,7 +32,7 @@ export declare abstract class Artifact {
|
|
|
32
32
|
readonly name: string;
|
|
33
33
|
readonly functions: FunctionSig[];
|
|
34
34
|
constructor(version: string, name: string, functions: FunctionSig[]);
|
|
35
|
-
abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
|
|
35
|
+
abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean, exposePrivateFunctions: boolean): string;
|
|
36
36
|
isDevnet(signer: SignerProvider): Promise<boolean>;
|
|
37
37
|
}
|
|
38
38
|
export declare class Contract extends Artifact {
|
|
@@ -48,11 +48,17 @@ export declare class Contract extends Artifact {
|
|
|
48
48
|
readonly stdInterfaceId?: HexString;
|
|
49
49
|
readonly bytecodeDebug: string;
|
|
50
50
|
readonly codeHashDebug: string;
|
|
51
|
-
readonly
|
|
51
|
+
readonly decodedContract: contract.Contract;
|
|
52
|
+
private bytecodeForTesting;
|
|
53
|
+
private codeHashForTesting;
|
|
52
54
|
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);
|
|
55
|
+
getByteCodeForTesting(): string;
|
|
56
|
+
hasCodeHash(hash: string): boolean;
|
|
57
|
+
getDecodedMethod(methodIndex: number): Method;
|
|
53
58
|
publicFunctions(): FunctionSig[];
|
|
54
59
|
usingPreapprovedAssetsFunctions(): FunctionSig[];
|
|
55
60
|
usingAssetsInContractFunctions(): FunctionSig[];
|
|
61
|
+
isMethodUsePreapprovedAssets(methodIndex: number): boolean;
|
|
56
62
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
|
|
57
63
|
static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
|
|
58
64
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
|
|
@@ -75,7 +81,7 @@ export declare class Contract extends Artifact {
|
|
|
75
81
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string, getContractByCodeHash: (codeHash: string) => Contract): ContractEvent;
|
|
76
82
|
fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string, getContractByCodeHash: (codeHash: string) => Contract): TestContractResult<unknown>;
|
|
77
83
|
txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
|
|
78
|
-
buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
|
|
84
|
+
buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean, exposePrivateFunctions?: boolean): string;
|
|
79
85
|
static fromApiEvents(events: node.ContractEventByTxId[], addressToCodeHash: Map<string, string>, txId: string, getContractByCodeHash: (codeHash: string) => Contract): ContractEvent[];
|
|
80
86
|
toApiCallContract<T extends Arguments>(params: CallContractParams<T>, groupIndex: number, contractAddress: string, methodIndex: number): node.CallContract;
|
|
81
87
|
fromApiCallContractResult(result: node.CallContractResult, txId: string, methodIndex: number, getContractByCodeHash: (codeHash: string) => Contract): CallContractResult<unknown>;
|
|
@@ -173,6 +179,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
|
|
|
173
179
|
issueTokenTo?: string;
|
|
174
180
|
gasAmount?: number;
|
|
175
181
|
gasPrice?: Number256;
|
|
182
|
+
exposePrivateFunctions?: boolean;
|
|
176
183
|
}
|
|
177
184
|
export type DeployContractResult<T extends ContractInstance> = Omit<SignDeployContractTxResult, 'contractId' | 'contractAddress' | 'groupIndex'> & {
|
|
178
185
|
contractInstance: T;
|
|
@@ -129,16 +129,46 @@ class Contract extends Artifact {
|
|
|
129
129
|
this.stdInterfaceId = stdInterfaceId;
|
|
130
130
|
this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch);
|
|
131
131
|
this.codeHashDebug = codeHashDebug;
|
|
132
|
-
this.
|
|
132
|
+
this.decodedContract = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(this.bytecode));
|
|
133
|
+
this.bytecodeForTesting = undefined;
|
|
134
|
+
this.codeHashForTesting = undefined;
|
|
135
|
+
}
|
|
136
|
+
getByteCodeForTesting() {
|
|
137
|
+
if (this.bytecodeForTesting !== undefined)
|
|
138
|
+
return this.bytecodeForTesting;
|
|
139
|
+
if (this.publicFunctions().length == this.functions.length) {
|
|
140
|
+
this.bytecodeForTesting = this.bytecodeDebug;
|
|
141
|
+
this.codeHashForTesting = this.codeHashDebug;
|
|
142
|
+
return this.bytecodeForTesting;
|
|
143
|
+
}
|
|
144
|
+
const decodedDebugContract = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(this.bytecodeDebug));
|
|
145
|
+
const methods = decodedDebugContract.methods.map((method) => ({ ...method, isPublic: true }));
|
|
146
|
+
const bytecodeForTesting = codec_1.contract.contractCodec.encodeContract({
|
|
147
|
+
fieldLength: decodedDebugContract.fieldLength,
|
|
148
|
+
methods: methods
|
|
149
|
+
});
|
|
150
|
+
const codeHashForTesting = blake.blake2b(bytecodeForTesting, undefined, 32);
|
|
151
|
+
this.bytecodeForTesting = (0, utils_1.binToHex)(bytecodeForTesting);
|
|
152
|
+
this.codeHashForTesting = (0, utils_1.binToHex)(codeHashForTesting);
|
|
153
|
+
return this.bytecodeForTesting;
|
|
154
|
+
}
|
|
155
|
+
hasCodeHash(hash) {
|
|
156
|
+
return this.codeHash === hash || this.codeHashDebug === hash || this.codeHashForTesting === hash;
|
|
157
|
+
}
|
|
158
|
+
getDecodedMethod(methodIndex) {
|
|
159
|
+
return this.decodedContract.methods[`${methodIndex}`];
|
|
133
160
|
}
|
|
134
161
|
publicFunctions() {
|
|
135
|
-
return this.functions.filter((_, index) => this.
|
|
162
|
+
return this.functions.filter((_, index) => this.getDecodedMethod(index).isPublic);
|
|
136
163
|
}
|
|
137
164
|
usingPreapprovedAssetsFunctions() {
|
|
138
|
-
return this.functions.filter((_, index) => this.
|
|
165
|
+
return this.functions.filter((_, index) => this.getDecodedMethod(index).usePreapprovedAssets);
|
|
139
166
|
}
|
|
140
167
|
usingAssetsInContractFunctions() {
|
|
141
|
-
return this.functions.filter((_, index) => this.
|
|
168
|
+
return this.functions.filter((_, index) => this.getDecodedMethod(index).useContractAssets);
|
|
169
|
+
}
|
|
170
|
+
isMethodUsePreapprovedAssets(methodIndex) {
|
|
171
|
+
return this.getDecodedMethod(methodIndex).usePreapprovedAssets;
|
|
142
172
|
}
|
|
143
173
|
// TODO: safely parse json
|
|
144
174
|
static fromJson(artifact, bytecodeDebugPatch = '', codeHashDebug = '', structs = []) {
|
|
@@ -333,7 +363,7 @@ class Contract extends Artifact {
|
|
|
333
363
|
async txParamsForDeployment(signer, params) {
|
|
334
364
|
const isDevnet = await this.isDevnet(signer);
|
|
335
365
|
const initialFields = params.initialFields ?? {};
|
|
336
|
-
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet);
|
|
366
|
+
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet, params.exposePrivateFunctions ?? false);
|
|
337
367
|
const selectedAccount = await signer.getSelectedAccount();
|
|
338
368
|
const signerParams = {
|
|
339
369
|
signerAddress: selectedAccount.address,
|
|
@@ -348,9 +378,14 @@ class Contract extends Artifact {
|
|
|
348
378
|
};
|
|
349
379
|
return signerParams;
|
|
350
380
|
}
|
|
351
|
-
buildByteCodeToDeploy(initialFields, isDevnet) {
|
|
381
|
+
buildByteCodeToDeploy(initialFields, isDevnet, exposePrivateFunctions = false) {
|
|
352
382
|
try {
|
|
353
|
-
|
|
383
|
+
const bytecode = exposePrivateFunctions && isDevnet
|
|
384
|
+
? this.getByteCodeForTesting()
|
|
385
|
+
: isDevnet
|
|
386
|
+
? this.bytecodeDebug
|
|
387
|
+
: this.bytecode;
|
|
388
|
+
return ralph.buildContractByteCode(bytecode, initialFields, this.fieldsSig, this.structs);
|
|
354
389
|
}
|
|
355
390
|
catch (error) {
|
|
356
391
|
throw new Error(`Failed to build bytecode for contract ${this.name}, error: ${error}`);
|
|
@@ -1074,7 +1109,7 @@ exports.callMethod = callMethod;
|
|
|
1074
1109
|
async function signExecuteMethod(contract, instance, methodName, params) {
|
|
1075
1110
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1076
1111
|
const functionSig = contract.contract.functions[methodIndex];
|
|
1077
|
-
const methodUsePreapprovedAssets = contract.contract.
|
|
1112
|
+
const methodUsePreapprovedAssets = contract.contract.isMethodUsePreapprovedAssets(methodIndex);
|
|
1078
1113
|
const bytecodeTemplate = getBytecodeTemplate(methodIndex, methodUsePreapprovedAssets, functionSig, contract.contract.structs, params.attoAlphAmount, params.tokens);
|
|
1079
1114
|
const fieldsSig = toFieldsSig(contract.contract.name, functionSig);
|
|
1080
1115
|
const bytecode = ralph.buildScriptByteCode(bytecodeTemplate, { __contract__: instance.contractId, ...params.args }, fieldsSig, contract.contract.structs);
|
|
@@ -1260,7 +1295,7 @@ async function multicallMethods(contract, instance, callss, getContractByCodeHas
|
|
|
1260
1295
|
});
|
|
1261
1296
|
const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams.flat() });
|
|
1262
1297
|
let callResultIndex = 0;
|
|
1263
|
-
|
|
1298
|
+
return callsParams.map((calls, index0) => {
|
|
1264
1299
|
const callsResult = {};
|
|
1265
1300
|
const entries = callEntries[`${index0}`];
|
|
1266
1301
|
calls.forEach((call, index1) => {
|
|
@@ -1272,7 +1307,6 @@ async function multicallMethods(contract, instance, callss, getContractByCodeHas
|
|
|
1272
1307
|
});
|
|
1273
1308
|
return callsResult;
|
|
1274
1309
|
});
|
|
1275
|
-
return results.length === 1 ? results[0] : results;
|
|
1276
1310
|
}
|
|
1277
1311
|
exports.multicallMethods = multicallMethods;
|
|
1278
1312
|
async function getContractEventsCurrentCount(contractAddress) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Alephium dev <dev@alephium.org>",
|
|
35
35
|
"config": {
|
|
36
|
-
"alephium_version": "3.
|
|
36
|
+
"alephium_version": "3.6.2",
|
|
37
37
|
"explorer_backend_version": "2.0.0"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -892,6 +892,18 @@ export interface Project {
|
|
|
892
892
|
compilerOptions?: CompilerOptions
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
+
/** RawBlock */
|
|
896
|
+
export interface RawBlock {
|
|
897
|
+
/** @format hex-string */
|
|
898
|
+
value: string
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** RawTransaction */
|
|
902
|
+
export interface RawTransaction {
|
|
903
|
+
/** @format hex-string */
|
|
904
|
+
value: string
|
|
905
|
+
}
|
|
906
|
+
|
|
895
907
|
/** Reachable */
|
|
896
908
|
export interface Reachable {
|
|
897
909
|
peers: string[]
|
|
@@ -966,6 +978,13 @@ export interface StructSig {
|
|
|
966
978
|
isMutable: boolean[]
|
|
967
979
|
}
|
|
968
980
|
|
|
981
|
+
/** SubContracts */
|
|
982
|
+
export interface SubContracts {
|
|
983
|
+
subContracts: string[]
|
|
984
|
+
/** @format int32 */
|
|
985
|
+
nextStart: number
|
|
986
|
+
}
|
|
987
|
+
|
|
969
988
|
/** SubmitMultisig */
|
|
970
989
|
export interface SubmitMultisig {
|
|
971
990
|
unsignedTx: string
|
|
@@ -1493,7 +1512,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1493
1512
|
|
|
1494
1513
|
/**
|
|
1495
1514
|
* @title Alephium API
|
|
1496
|
-
* @version 3.
|
|
1515
|
+
* @version 3.6.2
|
|
1497
1516
|
* @baseUrl ../
|
|
1498
1517
|
*/
|
|
1499
1518
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -2287,6 +2306,22 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2287
2306
|
method: 'GET',
|
|
2288
2307
|
format: 'json',
|
|
2289
2308
|
...params
|
|
2309
|
+
}).then(convertHttpResponse),
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* No description
|
|
2313
|
+
*
|
|
2314
|
+
* @tags Blockflow
|
|
2315
|
+
* @name GetBlockflowRawBlocksBlockHash
|
|
2316
|
+
* @summary Get raw block in hex format
|
|
2317
|
+
* @request GET:/blockflow/raw-blocks/{block_hash}
|
|
2318
|
+
*/
|
|
2319
|
+
getBlockflowRawBlocksBlockHash: (blockHash: string, params: RequestParams = {}) =>
|
|
2320
|
+
this.request<RawBlock, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2321
|
+
path: `/blockflow/raw-blocks/${blockHash}`,
|
|
2322
|
+
method: 'GET',
|
|
2323
|
+
format: 'json',
|
|
2324
|
+
...params
|
|
2290
2325
|
}).then(convertHttpResponse)
|
|
2291
2326
|
}
|
|
2292
2327
|
addresses = {
|
|
@@ -2474,6 +2509,32 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2474
2509
|
...params
|
|
2475
2510
|
}).then(convertHttpResponse),
|
|
2476
2511
|
|
|
2512
|
+
/**
|
|
2513
|
+
* No description
|
|
2514
|
+
*
|
|
2515
|
+
* @tags Transactions
|
|
2516
|
+
* @name GetTransactionsRawTxid
|
|
2517
|
+
* @summary Get raw transaction in hex format
|
|
2518
|
+
* @request GET:/transactions/raw/{txId}
|
|
2519
|
+
*/
|
|
2520
|
+
getTransactionsRawTxid: (
|
|
2521
|
+
txId: string,
|
|
2522
|
+
query?: {
|
|
2523
|
+
/** @format int32 */
|
|
2524
|
+
fromGroup?: number
|
|
2525
|
+
/** @format int32 */
|
|
2526
|
+
toGroup?: number
|
|
2527
|
+
},
|
|
2528
|
+
params: RequestParams = {}
|
|
2529
|
+
) =>
|
|
2530
|
+
this.request<RawTransaction, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2531
|
+
path: `/transactions/raw/${txId}`,
|
|
2532
|
+
method: 'GET',
|
|
2533
|
+
query: query,
|
|
2534
|
+
format: 'json',
|
|
2535
|
+
...params
|
|
2536
|
+
}).then(convertHttpResponse),
|
|
2537
|
+
|
|
2477
2538
|
/**
|
|
2478
2539
|
* No description
|
|
2479
2540
|
*
|
|
@@ -2499,6 +2560,31 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2499
2560
|
query: query,
|
|
2500
2561
|
format: 'json',
|
|
2501
2562
|
...params
|
|
2563
|
+
}).then(convertHttpResponse),
|
|
2564
|
+
|
|
2565
|
+
/**
|
|
2566
|
+
* No description
|
|
2567
|
+
*
|
|
2568
|
+
* @tags Transactions
|
|
2569
|
+
* @name GetTransactionsTxIdFromOutputref
|
|
2570
|
+
* @summary Get transaction id from transaction output ref
|
|
2571
|
+
* @request GET:/transactions/tx-id-from-outputref
|
|
2572
|
+
*/
|
|
2573
|
+
getTransactionsTxIdFromOutputref: (
|
|
2574
|
+
query: {
|
|
2575
|
+
/** @format int32 */
|
|
2576
|
+
hint: number
|
|
2577
|
+
/** @format 32-byte-hash */
|
|
2578
|
+
key: string
|
|
2579
|
+
},
|
|
2580
|
+
params: RequestParams = {}
|
|
2581
|
+
) =>
|
|
2582
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2583
|
+
path: `/transactions/tx-id-from-outputref`,
|
|
2584
|
+
method: 'GET',
|
|
2585
|
+
query: query,
|
|
2586
|
+
format: 'json',
|
|
2587
|
+
...params
|
|
2502
2588
|
}).then(convertHttpResponse)
|
|
2503
2589
|
}
|
|
2504
2590
|
mempool = {
|
|
@@ -2756,6 +2842,64 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2756
2842
|
...params
|
|
2757
2843
|
}).then(convertHttpResponse),
|
|
2758
2844
|
|
|
2845
|
+
/**
|
|
2846
|
+
* No description
|
|
2847
|
+
*
|
|
2848
|
+
* @tags Contracts
|
|
2849
|
+
* @name GetContractsAddressParent
|
|
2850
|
+
* @summary Get parent contract address
|
|
2851
|
+
* @request GET:/contracts/{address}/parent
|
|
2852
|
+
*/
|
|
2853
|
+
getContractsAddressParent: (address: string, params: RequestParams = {}) =>
|
|
2854
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2855
|
+
path: `/contracts/${address}/parent`,
|
|
2856
|
+
method: 'GET',
|
|
2857
|
+
format: 'json',
|
|
2858
|
+
...params
|
|
2859
|
+
}).then(convertHttpResponse),
|
|
2860
|
+
|
|
2861
|
+
/**
|
|
2862
|
+
* No description
|
|
2863
|
+
*
|
|
2864
|
+
* @tags Contracts
|
|
2865
|
+
* @name GetContractsAddressSubContracts
|
|
2866
|
+
* @summary Get sub-contract addresses
|
|
2867
|
+
* @request GET:/contracts/{address}/sub-contracts
|
|
2868
|
+
*/
|
|
2869
|
+
getContractsAddressSubContracts: (
|
|
2870
|
+
address: string,
|
|
2871
|
+
query: {
|
|
2872
|
+
/** @format int32 */
|
|
2873
|
+
start: number
|
|
2874
|
+
/** @format int32 */
|
|
2875
|
+
limit?: number
|
|
2876
|
+
},
|
|
2877
|
+
params: RequestParams = {}
|
|
2878
|
+
) =>
|
|
2879
|
+
this.request<SubContracts, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2880
|
+
path: `/contracts/${address}/sub-contracts`,
|
|
2881
|
+
method: 'GET',
|
|
2882
|
+
query: query,
|
|
2883
|
+
format: 'json',
|
|
2884
|
+
...params
|
|
2885
|
+
}).then(convertHttpResponse),
|
|
2886
|
+
|
|
2887
|
+
/**
|
|
2888
|
+
* No description
|
|
2889
|
+
*
|
|
2890
|
+
* @tags Contracts
|
|
2891
|
+
* @name GetContractsAddressSubContractsCurrentCount
|
|
2892
|
+
* @summary Get current value of the sub-contracts counter for a contract
|
|
2893
|
+
* @request GET:/contracts/{address}/sub-contracts/current-count
|
|
2894
|
+
*/
|
|
2895
|
+
getContractsAddressSubContractsCurrentCount: (address: string, params: RequestParams = {}) =>
|
|
2896
|
+
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2897
|
+
path: `/contracts/${address}/sub-contracts/current-count`,
|
|
2898
|
+
method: 'GET',
|
|
2899
|
+
format: 'json',
|
|
2900
|
+
...params
|
|
2901
|
+
}).then(convertHttpResponse),
|
|
2902
|
+
|
|
2759
2903
|
/**
|
|
2760
2904
|
* No description
|
|
2761
2905
|
*
|