@alephium/web3 1.1.2 → 1.2.1-rc.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/address/address.d.ts +1 -0
- package/dist/src/address/address.js +11 -1
- package/dist/src/api/api-alephium.d.ts +37 -2
- package/dist/src/api/api-alephium.js +17 -1
- package/dist/src/api/api-explorer.d.ts +814 -641
- package/dist/src/api/api-explorer.js +337 -310
- package/dist/src/contract/contract.d.ts +15 -3
- package/dist/src/contract/contract.js +36 -14
- package/package.json +3 -3
- package/src/address/address.ts +9 -0
- package/src/api/api-alephium.ts +51 -3
- package/src/api/api-explorer.ts +1022 -846
- package/src/contract/contract.ts +59 -17
- package/std/nft_interface.ral +20 -1
package/src/contract/contract.ts
CHANGED
|
@@ -77,7 +77,6 @@ import {
|
|
|
77
77
|
StoreMutFieldByIndex,
|
|
78
78
|
DestroySelf,
|
|
79
79
|
Pop,
|
|
80
|
-
byteStringCodec,
|
|
81
80
|
StoreLocal,
|
|
82
81
|
instrCodec,
|
|
83
82
|
U256Const,
|
|
@@ -603,20 +602,30 @@ export class Contract extends Artifact {
|
|
|
603
602
|
): CallContractResult<unknown> {
|
|
604
603
|
const returnTypes = this.functions[`${methodIndex}`].returnTypes
|
|
605
604
|
const callResult = tryGetCallResult(result)
|
|
606
|
-
|
|
607
|
-
|
|
605
|
+
return fromCallResult(callResult, txId, returnTypes, this.structs, getContractByCodeHash)
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
608
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
609
|
+
function fromCallResult(
|
|
610
|
+
callResult: node.CallContractSucceeded | node.CallTxScriptResult,
|
|
611
|
+
txId: string,
|
|
612
|
+
returnTypes: string[],
|
|
613
|
+
structs: Struct[],
|
|
614
|
+
getContractByCodeHash: (codeHash: string) => Contract
|
|
615
|
+
): CallContractResult<unknown> {
|
|
616
|
+
const rawReturn = fromApiArray(callResult.returns, returnTypes, structs)
|
|
617
|
+
const returns = rawReturn.length === 0 ? null : rawReturn.length === 1 ? rawReturn[0] : rawReturn
|
|
618
|
+
|
|
619
|
+
const addressToCodeHash = new Map<string, string>()
|
|
620
|
+
callResult.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
|
|
621
|
+
return {
|
|
622
|
+
returns: returns,
|
|
623
|
+
gasUsed: callResult.gasUsed,
|
|
624
|
+
contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
|
|
625
|
+
txInputs: callResult.txInputs,
|
|
626
|
+
txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
|
|
627
|
+
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash),
|
|
628
|
+
debugMessages: callResult.debugMessages
|
|
620
629
|
}
|
|
621
630
|
}
|
|
622
631
|
|
|
@@ -1011,17 +1020,38 @@ export abstract class ContractFactory<I extends ContractInstance, F extends Fiel
|
|
|
1011
1020
|
}
|
|
1012
1021
|
}
|
|
1013
1022
|
|
|
1014
|
-
export class ExecutableScript<P extends Fields = Fields> {
|
|
1023
|
+
export class ExecutableScript<P extends Fields = Fields, R extends Val | null = null> {
|
|
1015
1024
|
readonly script: Script
|
|
1025
|
+
readonly getContractByCodeHash: (codeHash: string) => Contract
|
|
1016
1026
|
|
|
1017
|
-
constructor(script: Script) {
|
|
1027
|
+
constructor(script: Script, getContractByCodeHash: (codeHash: string) => Contract) {
|
|
1018
1028
|
this.script = script
|
|
1029
|
+
this.getContractByCodeHash = getContractByCodeHash
|
|
1019
1030
|
}
|
|
1020
1031
|
|
|
1021
1032
|
async execute(signer: SignerProvider, params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult> {
|
|
1022
1033
|
const signerParams = await this.script.txParamsForExecution(signer, params)
|
|
1023
1034
|
return await signer.signAndSubmitExecuteScriptTx(signerParams)
|
|
1024
1035
|
}
|
|
1036
|
+
|
|
1037
|
+
async call(params: CallScriptParams<P>): Promise<CallScriptResult<R>> {
|
|
1038
|
+
const mainFunc = this.script.functions.find((f) => f.name === 'main')
|
|
1039
|
+
if (mainFunc === undefined) {
|
|
1040
|
+
throw new Error(`There is no main function in script ${this.script.name}`)
|
|
1041
|
+
}
|
|
1042
|
+
const bytecode = this.script.buildByteCodeToDeploy(params.initialFields)
|
|
1043
|
+
const txId = params.txId ?? randomTxId()
|
|
1044
|
+
const provider = getCurrentNodeProvider()
|
|
1045
|
+
const callResult = await provider.contracts.postContractsCallTxScript({
|
|
1046
|
+
...params,
|
|
1047
|
+
group: params.groupIndex ?? 0,
|
|
1048
|
+
bytecode: bytecode,
|
|
1049
|
+
inputAssets: toApiInputAssets(params.inputAssets)
|
|
1050
|
+
})
|
|
1051
|
+
const returnTypes = mainFunc.returnTypes
|
|
1052
|
+
const result = fromCallResult(callResult, txId, returnTypes, this.script.structs, this.getContractByCodeHash)
|
|
1053
|
+
return result as CallScriptResult<R>
|
|
1054
|
+
}
|
|
1025
1055
|
}
|
|
1026
1056
|
|
|
1027
1057
|
export interface ExecuteScriptParams<P extends Fields = Fields> {
|
|
@@ -1041,11 +1071,23 @@ export interface ExecuteScriptResult {
|
|
|
1041
1071
|
gasPrice: Number256
|
|
1042
1072
|
}
|
|
1043
1073
|
|
|
1074
|
+
export interface CallScriptParams<P extends Fields = Fields> {
|
|
1075
|
+
initialFields: P
|
|
1076
|
+
groupIndex?: number
|
|
1077
|
+
callerAddress?: string
|
|
1078
|
+
worldStateBlockHash?: string
|
|
1079
|
+
txId?: string
|
|
1080
|
+
interestedContracts?: string[]
|
|
1081
|
+
inputAssets?: InputAsset[]
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
export type CallScriptResult<R> = CallContractResult<R>
|
|
1085
|
+
|
|
1044
1086
|
export interface CallContractParams<T extends Arguments = Arguments> {
|
|
1045
1087
|
args: T
|
|
1046
1088
|
worldStateBlockHash?: string
|
|
1047
1089
|
txId?: string
|
|
1048
|
-
|
|
1090
|
+
interestedContracts?: string[]
|
|
1049
1091
|
inputAssets?: InputAsset[]
|
|
1050
1092
|
}
|
|
1051
1093
|
|
package/std/nft_interface.ral
CHANGED
|
@@ -14,11 +14,30 @@ Interface INFT {
|
|
|
14
14
|
// },
|
|
15
15
|
// "description": {
|
|
16
16
|
// "type": "string",
|
|
17
|
-
// "description": "General description of the NFT"
|
|
17
|
+
// "description": "General description of the NFT",
|
|
18
|
+
// "nullable": true
|
|
18
19
|
// },
|
|
19
20
|
// "image": {
|
|
20
21
|
// "type": "string",
|
|
21
22
|
// "description": "A URI to the image that represents the NFT"
|
|
23
|
+
// },
|
|
24
|
+
// "attributes": {
|
|
25
|
+
// "type": "array",
|
|
26
|
+
// "description": "An array of attributes for the NFT",
|
|
27
|
+
// "items": {
|
|
28
|
+
// "type": "object",
|
|
29
|
+
// "properties": {
|
|
30
|
+
// "trait_type": {
|
|
31
|
+
// "type": "string",
|
|
32
|
+
// "description": "The type of trait"
|
|
33
|
+
// },
|
|
34
|
+
// "value": {
|
|
35
|
+
// "type": ["string", "number", "boolean"],
|
|
36
|
+
// "description": "The value of the trait"
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
39
|
+
// },
|
|
40
|
+
// "nullable": true
|
|
22
41
|
// }
|
|
23
42
|
// }
|
|
24
43
|
// }
|