@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
|
@@ -823,3 +823,5 @@ export declare class InstrCodec extends Codec<Instr> {
|
|
|
823
823
|
}
|
|
824
824
|
export declare const instrCodec: InstrCodec;
|
|
825
825
|
export declare const instrsCodec: ArrayCodec<Instr>;
|
|
826
|
+
export declare function toU256(number: bigint): Instr;
|
|
827
|
+
export declare function toI256(number: bigint): Instr;
|
|
@@ -4,7 +4,7 @@ exports.I256Add = exports.BoolToByteVec = exports.BoolNeq = exports.BoolEq = exp
|
|
|
4
4
|
exports.Sha3 = exports.Sha256 = exports.Keccak256 = exports.Blake2b = exports.Assert = exports.IfFalse = exports.IfTrue = exports.Jump = exports.IsContractAddress = exports.IsAssetAddress = exports.AddressToByteVec = exports.AddressNeq = exports.AddressEq = exports.ByteVecConcat = exports.ByteVecSize = exports.ByteVecNeq = exports.ByteVecEq = exports.U256ToByteVec = exports.U256ToI256 = exports.I256ToByteVec = exports.I256ToU256 = exports.U256SHR = exports.U256SHL = exports.U256Xor = exports.U256BitOr = exports.U256BitAnd = exports.U256ModMul = exports.U256ModSub = exports.U256ModAdd = exports.U256Ge = exports.U256Gt = exports.U256Le = exports.U256Lt = exports.U256Neq = exports.U256Eq = exports.U256Mod = exports.U256Div = exports.U256Mul = exports.U256Sub = exports.U256Add = exports.I256Ge = exports.I256Gt = exports.I256Le = exports.I256Lt = exports.I256Neq = exports.I256Eq = exports.I256Mod = exports.I256Div = exports.I256Mul = exports.I256Sub = void 0;
|
|
5
5
|
exports.U256Exp = exports.I256Exp = exports.TxGasFee = exports.TxGasAmount = exports.TxGasPrice = exports.DEBUG = exports.BlockHash = exports.Swap = exports.AssertWithErrorCode = exports.Dup = exports.StoreLocalByIndex = exports.LoadLocalByIndex = exports.ContractIdToAddress = exports.Log9 = exports.Log8 = exports.Log7 = exports.Log6 = exports.EthEcRecover = exports.U256From32Byte = exports.U256From16Byte = exports.U256From8Byte = exports.U256From4Byte = exports.U256From2Byte = exports.U256From1Byte = exports.U256To32Byte = exports.U256To16Byte = exports.U256To8Byte = exports.U256To4Byte = exports.U256To2Byte = exports.U256To1Byte = exports.Zeros = exports.Encode = exports.ByteVecToAddress = exports.ByteVecSlice = exports.Log5 = exports.Log4 = exports.Log3 = exports.Log2 = exports.Log1 = exports.VerifyRelativeLocktime = exports.VerifyAbsoluteLocktime = exports.TxInputsSize = exports.TxInputAddressAt = exports.TxId = exports.BlockTarget = exports.BlockTimeStamp = exports.NetworkId = exports.VerifyED25519 = exports.VerifySecP256K1 = exports.VerifyTxSignature = void 0;
|
|
6
6
|
exports.CreateSubContractAndTransferToken = exports.CopyCreateContractAndTransferToken = exports.CreateContractAndTransferToken = exports.ContractExists = exports.StoreMutFieldByIndex = exports.LoadMutFieldByIndex = exports.CopyCreateSubContractWithToken = exports.CopyCreateSubContract = exports.CreateSubContractWithToken = exports.CreateSubContract = exports.LockApprovedAssets = exports.BurnToken = exports.CopyCreateContractWithToken = exports.MigrateWithFields = exports.MigrateSimple = exports.ContractCodeHash = exports.ContractInitialStateHash = exports.CallerCodeHash = exports.CallerInitialStateHash = exports.IsCalledFromTxScript = exports.CallerAddress = exports.CallerContractId = exports.SelfAddress = exports.SelfContractId = exports.DestroySelf = exports.CopyCreateContract = exports.CreateContractWithToken = exports.CreateContract = exports.TransferTokenToSelf = exports.TransferTokenFromSelf = exports.TransferToken = exports.TransferAlphToSelf = exports.TransferAlphFromSelf = exports.TransferAlph = exports.IsPaying = exports.TokenRemaining = exports.AlphRemaining = exports.ApproveToken = exports.ApproveAlph = exports.StoreMutField = exports.LoadMutField = exports.GroupOfAddress = exports.BoolToString = exports.I256ToString = exports.U256ToString = exports.AddModN = exports.MulModN = exports.GetSegregatedSignature = exports.VerifyBIP340Schnorr = exports.U256ModExp = void 0;
|
|
7
|
-
exports.instrsCodec = exports.instrCodec = exports.InstrCodec = exports.CallExternalBySelector = exports.MethodSelector = exports.CreateMapEntry = exports.MinimalContractDeposit = exports.PayGasFee = exports.LoadImmFieldByIndex = exports.LoadImmField = exports.ALPHTokenId = exports.SubContractIdOf = exports.SubContractId = exports.NullContractAddress = exports.CopyCreateSubContractAndTransferToken = void 0;
|
|
7
|
+
exports.toI256 = exports.toU256 = exports.instrsCodec = exports.instrCodec = exports.InstrCodec = exports.CallExternalBySelector = exports.MethodSelector = exports.CreateMapEntry = exports.MinimalContractDeposit = exports.PayGasFee = exports.LoadImmFieldByIndex = exports.LoadImmField = exports.ALPHTokenId = exports.SubContractIdOf = exports.SubContractId = exports.NullContractAddress = exports.CopyCreateSubContractAndTransferToken = void 0;
|
|
8
8
|
/*
|
|
9
9
|
Copyright 2018 - 2022 The Alephium Authors
|
|
10
10
|
This file is part of the alephium project.
|
|
@@ -1090,3 +1090,56 @@ class InstrCodec extends codec_1.Codec {
|
|
|
1090
1090
|
exports.InstrCodec = InstrCodec;
|
|
1091
1091
|
exports.instrCodec = new InstrCodec();
|
|
1092
1092
|
exports.instrsCodec = new array_codec_1.ArrayCodec(exports.instrCodec);
|
|
1093
|
+
function checkU256(number) {
|
|
1094
|
+
if (number < 0n || number >= 2n ** 256n) {
|
|
1095
|
+
throw new Error(`Invalid u256 number: ${number}`);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function toU256(number) {
|
|
1099
|
+
checkU256(number);
|
|
1100
|
+
switch (number) {
|
|
1101
|
+
case 0n:
|
|
1102
|
+
return exports.U256Const0;
|
|
1103
|
+
case 1n:
|
|
1104
|
+
return exports.U256Const1;
|
|
1105
|
+
case 2n:
|
|
1106
|
+
return exports.U256Const2;
|
|
1107
|
+
case 3n:
|
|
1108
|
+
return exports.U256Const3;
|
|
1109
|
+
case 4n:
|
|
1110
|
+
return exports.U256Const4;
|
|
1111
|
+
case 5n:
|
|
1112
|
+
return exports.U256Const5;
|
|
1113
|
+
default:
|
|
1114
|
+
return (0, exports.U256Const)(number);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
exports.toU256 = toU256;
|
|
1118
|
+
function checkI256(number) {
|
|
1119
|
+
const upperBound = 2n ** 255n;
|
|
1120
|
+
if (number < -upperBound || number >= upperBound) {
|
|
1121
|
+
throw new Error(`Invalid i256 number: ${number}`);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
function toI256(number) {
|
|
1125
|
+
checkI256(number);
|
|
1126
|
+
switch (number) {
|
|
1127
|
+
case 0n:
|
|
1128
|
+
return exports.I256Const0;
|
|
1129
|
+
case 1n:
|
|
1130
|
+
return exports.I256Const1;
|
|
1131
|
+
case 2n:
|
|
1132
|
+
return exports.I256Const2;
|
|
1133
|
+
case 3n:
|
|
1134
|
+
return exports.I256Const3;
|
|
1135
|
+
case 4n:
|
|
1136
|
+
return exports.I256Const4;
|
|
1137
|
+
case 5n:
|
|
1138
|
+
return exports.I256Const5;
|
|
1139
|
+
case -1n:
|
|
1140
|
+
return exports.I256ConstN1;
|
|
1141
|
+
default:
|
|
1142
|
+
return (0, exports.I256Const)(number);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
exports.toI256 = toI256;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unlockScriptCodec = void 0;
|
|
3
|
+
exports.encodedSameAsPrevious = exports.unlockScriptCodec = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -47,3 +47,4 @@ exports.unlockScriptCodec = new codec_1.EnumCodec('unlock script', {
|
|
|
47
47
|
P2SH: p2shCodec,
|
|
48
48
|
SameAsPrevious: sameAsPreviousCodec
|
|
49
49
|
});
|
|
50
|
+
exports.encodedSameAsPrevious = exports.unlockScriptCodec.encode({ kind: 'SameAsPrevious', value: 'SameAsPrevious' });
|
package/dist/src/constants.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ export declare const MIN_UTXO_SET_AMOUNT: bigint;
|
|
|
4
4
|
export declare const ALPH_TOKEN_ID: string;
|
|
5
5
|
export declare const ONE_ALPH: bigint;
|
|
6
6
|
export declare const DUST_AMOUNT: bigint;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated `ZERO_ADDRESS` is deprecated. Use `NULL_CONTRACT_ADDRESS` instead.
|
|
9
|
+
*/
|
|
7
10
|
export declare const ZERO_ADDRESS = "tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq";
|
|
11
|
+
export declare const NULL_CONTRACT_ADDRESS = "tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq";
|
|
8
12
|
export declare const DEFAULT_GAS_AMOUNT = 20000;
|
|
9
13
|
export declare const DEFAULT_GAS_PRICE: bigint;
|
|
10
14
|
export declare const DEFAULT_GAS_ATTOALPH_AMOUNT: bigint;
|
package/dist/src/constants.js
CHANGED
|
@@ -17,14 +17,18 @@ 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.MAP_ENTRY_DEPOSIT = exports.MINIMAL_CONTRACT_DEPOSIT = exports.DEFAULT_GAS_ALPH_AMOUNT = exports.DEFAULT_GAS_ATTOALPH_AMOUNT = exports.DEFAULT_GAS_PRICE = exports.DEFAULT_GAS_AMOUNT = exports.ZERO_ADDRESS = exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.MAP_ENTRY_DEPOSIT = exports.MINIMAL_CONTRACT_DEPOSIT = exports.DEFAULT_GAS_ALPH_AMOUNT = exports.DEFAULT_GAS_ATTOALPH_AMOUNT = exports.DEFAULT_GAS_PRICE = exports.DEFAULT_GAS_AMOUNT = exports.NULL_CONTRACT_ADDRESS = exports.ZERO_ADDRESS = exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
22
|
exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS * exports.TOTAL_NUMBER_OF_GROUPS;
|
|
23
23
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
24
24
|
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
25
25
|
exports.ONE_ALPH = 10n ** 18n;
|
|
26
26
|
exports.DUST_AMOUNT = 10n ** 15n;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated `ZERO_ADDRESS` is deprecated. Use `NULL_CONTRACT_ADDRESS` instead.
|
|
29
|
+
*/
|
|
27
30
|
exports.ZERO_ADDRESS = 'tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq';
|
|
31
|
+
exports.NULL_CONTRACT_ADDRESS = 'tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq';
|
|
28
32
|
exports.DEFAULT_GAS_AMOUNT = 20000;
|
|
29
33
|
exports.DEFAULT_GAS_PRICE = 10n ** 11n;
|
|
30
34
|
exports.DEFAULT_GAS_ATTOALPH_AMOUNT = BigInt(exports.DEFAULT_GAS_AMOUNT) * exports.DEFAULT_GAS_PRICE;
|
|
@@ -50,15 +50,18 @@ export declare class Contract extends Artifact {
|
|
|
50
50
|
readonly codeHashDebug: string;
|
|
51
51
|
readonly decodedContract: contract.Contract;
|
|
52
52
|
private bytecodeForTesting;
|
|
53
|
+
private decodedTestingContract;
|
|
53
54
|
private codeHashForTesting;
|
|
54
55
|
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);
|
|
56
|
+
isInlineFunc(index: number): boolean;
|
|
55
57
|
getByteCodeForTesting(): string;
|
|
58
|
+
getDecodedTestingContract(): contract.Contract;
|
|
56
59
|
hasCodeHash(hash: string): boolean;
|
|
57
60
|
getDecodedMethod(methodIndex: number): Method;
|
|
58
61
|
publicFunctions(): FunctionSig[];
|
|
59
62
|
usingPreapprovedAssetsFunctions(): FunctionSig[];
|
|
60
63
|
usingAssetsInContractFunctions(): FunctionSig[];
|
|
61
|
-
isMethodUsePreapprovedAssets(methodIndex: number): boolean;
|
|
64
|
+
isMethodUsePreapprovedAssets(isDevnet: boolean, methodIndex: number): boolean;
|
|
62
65
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
|
|
63
66
|
static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
|
|
64
67
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
|
|
@@ -314,4 +317,5 @@ export declare function multicallMethods<I extends ContractInstance, F extends F
|
|
|
314
317
|
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
315
318
|
export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
316
319
|
export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
320
|
+
export declare function getContractCodeByCodeHash(nodeProvider: NodeProvider, codeHash: HexString): Promise<HexString | undefined>;
|
|
317
321
|
export {};
|
|
@@ -40,7 +40,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
40
40
|
return result;
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.signExecuteMethod = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.printDebugMessagesFromTx = exports.getDebugMessagesFromTx = exports.testMethod = exports.extractMapsFromApiResult = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
43
|
+
exports.getContractCodeByCodeHash = exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.signExecuteMethod = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.printDebugMessagesFromTx = exports.getDebugMessagesFromTx = exports.testMethod = exports.extractMapsFromApiResult = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
44
44
|
const fs_1 = require("fs");
|
|
45
45
|
const api_1 = require("../api");
|
|
46
46
|
const ralph = __importStar(require("./ralph"));
|
|
@@ -133,12 +133,21 @@ class Contract extends Artifact {
|
|
|
133
133
|
this.codeHashDebug = codeHashDebug;
|
|
134
134
|
this.decodedContract = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(this.bytecode));
|
|
135
135
|
this.bytecodeForTesting = undefined;
|
|
136
|
+
this.decodedTestingContract = undefined;
|
|
136
137
|
this.codeHashForTesting = undefined;
|
|
137
138
|
}
|
|
139
|
+
isInlineFunc(index) {
|
|
140
|
+
if (index >= this.functions.length) {
|
|
141
|
+
throw new Error(`Invalid function index ${index}, function size: ${this.functions.length}`);
|
|
142
|
+
}
|
|
143
|
+
const inlineFuncFromIndex = this.decodedContract.methods.length;
|
|
144
|
+
return index >= inlineFuncFromIndex;
|
|
145
|
+
}
|
|
138
146
|
getByteCodeForTesting() {
|
|
139
147
|
if (this.bytecodeForTesting !== undefined)
|
|
140
148
|
return this.bytecodeForTesting;
|
|
141
|
-
|
|
149
|
+
const hasInlineFunction = this.functions.length > this.decodedContract.methods.length;
|
|
150
|
+
if (!hasInlineFunction && this.publicFunctions().length == this.functions.length) {
|
|
142
151
|
this.bytecodeForTesting = this.bytecodeDebug;
|
|
143
152
|
this.codeHashForTesting = this.codeHashDebug;
|
|
144
153
|
return this.bytecodeForTesting;
|
|
@@ -154,6 +163,13 @@ class Contract extends Artifact {
|
|
|
154
163
|
this.codeHashForTesting = (0, utils_1.binToHex)(codeHashForTesting);
|
|
155
164
|
return this.bytecodeForTesting;
|
|
156
165
|
}
|
|
166
|
+
getDecodedTestingContract() {
|
|
167
|
+
if (this.decodedTestingContract !== undefined)
|
|
168
|
+
return this.decodedTestingContract;
|
|
169
|
+
const bytecodeForTesting = (0, utils_1.hexToBinUnsafe)(this.getByteCodeForTesting());
|
|
170
|
+
this.decodedTestingContract = codec_1.contract.contractCodec.decodeContract(bytecodeForTesting);
|
|
171
|
+
return this.decodedTestingContract;
|
|
172
|
+
}
|
|
157
173
|
hasCodeHash(hash) {
|
|
158
174
|
return this.codeHash === hash || this.codeHashDebug === hash || this.codeHashForTesting === hash;
|
|
159
175
|
}
|
|
@@ -169,8 +185,11 @@ class Contract extends Artifact {
|
|
|
169
185
|
usingAssetsInContractFunctions() {
|
|
170
186
|
return this.functions.filter((_, index) => this.getDecodedMethod(index).useContractAssets);
|
|
171
187
|
}
|
|
172
|
-
isMethodUsePreapprovedAssets(methodIndex) {
|
|
173
|
-
|
|
188
|
+
isMethodUsePreapprovedAssets(isDevnet, methodIndex) {
|
|
189
|
+
if (!isDevnet || !this.isInlineFunc(methodIndex))
|
|
190
|
+
return this.getDecodedMethod(methodIndex).usePreapprovedAssets;
|
|
191
|
+
const contract = this.getDecodedTestingContract();
|
|
192
|
+
return contract.methods[`${methodIndex}`].usePreapprovedAssets;
|
|
174
193
|
}
|
|
175
194
|
// TODO: safely parse json
|
|
176
195
|
static fromJson(artifact, bytecodeDebugPatch = '', codeHashDebug = '', structs = []) {
|
|
@@ -284,6 +303,7 @@ class Contract extends Artifact {
|
|
|
284
303
|
: ralph.flattenFields(params.initialFields, this.fieldsSig.names, this.fieldsSig.types, this.fieldsSig.isMutable, this.structs);
|
|
285
304
|
const immFields = allFields.filter((f) => !f.isMutable).map((f) => (0, api_1.toApiVal)(f.value, f.type));
|
|
286
305
|
const mutFields = allFields.filter((f) => f.isMutable).map((f) => (0, api_1.toApiVal)(f.value, f.type));
|
|
306
|
+
const methodIndex = this.getMethodIndex(funcName);
|
|
287
307
|
return {
|
|
288
308
|
group: params.group,
|
|
289
309
|
blockHash: params.blockHash,
|
|
@@ -291,11 +311,11 @@ class Contract extends Artifact {
|
|
|
291
311
|
txId: params.txId,
|
|
292
312
|
address: params.address,
|
|
293
313
|
callerAddress: params.callerAddress,
|
|
294
|
-
bytecode: this.bytecodeDebug,
|
|
314
|
+
bytecode: this.isInlineFunc(methodIndex) ? this.getByteCodeForTesting() : this.bytecodeDebug,
|
|
295
315
|
initialImmFields: immFields,
|
|
296
316
|
initialMutFields: mutFields,
|
|
297
317
|
initialAsset: typeof params.initialAsset !== 'undefined' ? toApiAsset(params.initialAsset) : undefined,
|
|
298
|
-
methodIndex
|
|
318
|
+
methodIndex,
|
|
299
319
|
args: this.toApiArgs(funcName, params.testArgs),
|
|
300
320
|
existingContracts: this.toApiContractStates(params.existingContracts),
|
|
301
321
|
inputAssets: toApiInputAssets(params.inputAssets)
|
|
@@ -1190,7 +1210,8 @@ exports.callMethod = callMethod;
|
|
|
1190
1210
|
async function signExecuteMethod(contract, instance, methodName, params) {
|
|
1191
1211
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1192
1212
|
const functionSig = contract.contract.functions[methodIndex];
|
|
1193
|
-
const
|
|
1213
|
+
const isDevnet = await contract.contract.isDevnet(params.signer);
|
|
1214
|
+
const methodUsePreapprovedAssets = contract.contract.isMethodUsePreapprovedAssets(isDevnet, methodIndex);
|
|
1194
1215
|
const bytecodeTemplate = getBytecodeTemplate(methodIndex, methodUsePreapprovedAssets, functionSig, contract.contract.structs, params.attoAlphAmount, params.tokens);
|
|
1195
1216
|
const fieldsSig = toFieldsSig(contract.contract.name, functionSig);
|
|
1196
1217
|
const bytecode = ralph.buildScriptByteCode(bytecodeTemplate, { __contract__: instance.contractId, ...params.args }, fieldsSig, contract.contract.structs);
|
|
@@ -1206,7 +1227,7 @@ async function signExecuteMethod(contract, instance, methodName, params) {
|
|
|
1206
1227
|
gasPrice: params.gasPrice
|
|
1207
1228
|
};
|
|
1208
1229
|
const result = await signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
1209
|
-
if ((0, debug_1.isContractDebugMessageEnabled)() &&
|
|
1230
|
+
if ((0, debug_1.isContractDebugMessageEnabled)() && isDevnet) {
|
|
1210
1231
|
await printDebugMessagesFromTx(result.txId, signer.nodeProvider);
|
|
1211
1232
|
}
|
|
1212
1233
|
return result;
|
|
@@ -1418,3 +1439,18 @@ const getContractIdFromUnsignedTx = async (nodeProvider, unsignedTx) => {
|
|
|
1418
1439
|
exports.getContractIdFromUnsignedTx = getContractIdFromUnsignedTx;
|
|
1419
1440
|
// This function only works in the simple case where a single non-subcontract is created in the tx
|
|
1420
1441
|
exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx;
|
|
1442
|
+
async function getContractCodeByCodeHash(nodeProvider, codeHash) {
|
|
1443
|
+
if ((0, utils_1.isHexString)(codeHash) && codeHash.length === 64) {
|
|
1444
|
+
try {
|
|
1445
|
+
return await nodeProvider.contracts.getContractsCodehashCode(codeHash);
|
|
1446
|
+
}
|
|
1447
|
+
catch (error) {
|
|
1448
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
1449
|
+
return undefined;
|
|
1450
|
+
}
|
|
1451
|
+
throw new error_1.TraceableError(`Failed to get contract by code hash ${codeHash}`, error);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
throw new Error(`Invalid code hash: ${codeHash}`);
|
|
1455
|
+
}
|
|
1456
|
+
exports.getContractCodeByCodeHash = getContractCodeByCodeHash;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Val } from '../api';
|
|
2
|
+
import { Instr } from '../codec';
|
|
3
|
+
import { SignExecuteScriptTxParams } from '../signer';
|
|
4
|
+
import { HexString } from '../utils';
|
|
5
|
+
export declare class DappTransactionBuilder {
|
|
6
|
+
readonly callerAddress: string;
|
|
7
|
+
private callerLockupScript;
|
|
8
|
+
private approvedAssets;
|
|
9
|
+
private instrs;
|
|
10
|
+
constructor(callerAddress: string);
|
|
11
|
+
callContract(params: {
|
|
12
|
+
contractAddress: string;
|
|
13
|
+
methodIndex: number;
|
|
14
|
+
args: Val[];
|
|
15
|
+
attoAlphAmount?: bigint;
|
|
16
|
+
tokens?: {
|
|
17
|
+
id: HexString;
|
|
18
|
+
amount: bigint;
|
|
19
|
+
}[];
|
|
20
|
+
retLength?: number;
|
|
21
|
+
}): this;
|
|
22
|
+
getResult(): SignExecuteScriptTxParams;
|
|
23
|
+
private addTokenToMap;
|
|
24
|
+
private approveTokens;
|
|
25
|
+
}
|
|
26
|
+
export declare function genArgs(args: Val[]): Instr[];
|
|
@@ -0,0 +1,187 @@
|
|
|
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.genArgs = exports.DappTransactionBuilder = void 0;
|
|
21
|
+
const address_1 = require("../address");
|
|
22
|
+
const codec_1 = require("../codec");
|
|
23
|
+
const lockup_script_codec_1 = require("../codec/lockup-script-codec");
|
|
24
|
+
const script_codec_1 = require("../codec/script-codec");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const error_1 = require("../error");
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
|
+
class DappTransactionBuilder {
|
|
29
|
+
constructor(callerAddress) {
|
|
30
|
+
this.callerAddress = callerAddress;
|
|
31
|
+
try {
|
|
32
|
+
this.callerLockupScript = lockup_script_codec_1.lockupScriptCodec.decode((0, utils_1.base58ToBytes)(this.callerAddress));
|
|
33
|
+
if (this.callerLockupScript.kind !== 'P2PKH' && this.callerLockupScript.kind !== 'P2SH') {
|
|
34
|
+
throw new Error(`Expected a P2PKH address or P2SH address`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new error_1.TraceableError(`Invalid caller address: ${callerAddress}`, error);
|
|
39
|
+
}
|
|
40
|
+
this.approvedAssets = new Map();
|
|
41
|
+
this.instrs = [];
|
|
42
|
+
}
|
|
43
|
+
callContract(params) {
|
|
44
|
+
if (!(0, utils_1.isBase58)(params.contractAddress)) {
|
|
45
|
+
throw new Error(`Invalid contract address: ${params.contractAddress}, expected a base58 string`);
|
|
46
|
+
}
|
|
47
|
+
if (!(0, address_1.isContractAddress)(params.contractAddress)) {
|
|
48
|
+
throw new Error(`Invalid contract address: ${params.contractAddress}, expected a P2C address`);
|
|
49
|
+
}
|
|
50
|
+
if (params.methodIndex < 0) {
|
|
51
|
+
throw new Error(`Invalid method index: ${params.methodIndex}`);
|
|
52
|
+
}
|
|
53
|
+
const allTokens = (params.tokens ?? []).concat([{ id: constants_1.ALPH_TOKEN_ID, amount: params.attoAlphAmount ?? 0n }]);
|
|
54
|
+
const instrs = [
|
|
55
|
+
...genApproveAssets(this.callerLockupScript, this.approveTokens(allTokens)),
|
|
56
|
+
...genContractCall(params.contractAddress, params.methodIndex, params.args, params.retLength ?? 0)
|
|
57
|
+
];
|
|
58
|
+
this.instrs.push(...instrs);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
getResult() {
|
|
62
|
+
const method = {
|
|
63
|
+
isPublic: true,
|
|
64
|
+
usePreapprovedAssets: this.approvedAssets.size > 0,
|
|
65
|
+
useContractAssets: false,
|
|
66
|
+
usePayToContractOnly: false,
|
|
67
|
+
argsLength: 0,
|
|
68
|
+
localsLength: 0,
|
|
69
|
+
returnLength: 0,
|
|
70
|
+
instrs: this.instrs
|
|
71
|
+
};
|
|
72
|
+
const script = { methods: [method] };
|
|
73
|
+
const bytecode = script_codec_1.scriptCodec.encode(script);
|
|
74
|
+
const tokens = Array.from(this.approvedAssets.entries()).map(([id, amount]) => ({ id, amount }));
|
|
75
|
+
this.approvedAssets.clear();
|
|
76
|
+
this.instrs = [];
|
|
77
|
+
return {
|
|
78
|
+
signerAddress: this.callerAddress,
|
|
79
|
+
signerKeyType: this.callerLockupScript.kind === 'P2PKH' ? 'default' : 'bip340-schnorr',
|
|
80
|
+
bytecode: (0, utils_1.binToHex)(bytecode),
|
|
81
|
+
attoAlphAmount: tokens.find((t) => t.id === constants_1.ALPH_TOKEN_ID)?.amount,
|
|
82
|
+
tokens: tokens.filter((t) => t.id !== constants_1.ALPH_TOKEN_ID)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
addTokenToMap(tokenId, amount, map) {
|
|
86
|
+
const current = map.get(tokenId);
|
|
87
|
+
if (current !== undefined) {
|
|
88
|
+
map.set(tokenId, current + amount);
|
|
89
|
+
}
|
|
90
|
+
else if (amount > 0n) {
|
|
91
|
+
map.set(tokenId, amount);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
approveTokens(tokens) {
|
|
95
|
+
const tokenAmounts = new Map();
|
|
96
|
+
tokens.forEach((token) => {
|
|
97
|
+
if (!((0, utils_1.isHexString)(token.id) && token.id.length === 64)) {
|
|
98
|
+
throw new Error(`Invalid token id: ${token.id}`);
|
|
99
|
+
}
|
|
100
|
+
if (token.amount < 0n) {
|
|
101
|
+
throw new Error(`Invalid token amount: ${token.amount}`);
|
|
102
|
+
}
|
|
103
|
+
this.addTokenToMap(token.id, token.amount, tokenAmounts);
|
|
104
|
+
this.addTokenToMap(token.id, token.amount, this.approvedAssets);
|
|
105
|
+
});
|
|
106
|
+
return Array.from(tokenAmounts.entries()).map(([id, amount]) => ({ id, amount }));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DappTransactionBuilder = DappTransactionBuilder;
|
|
110
|
+
function genApproveAssets(callerLockupScript, tokens) {
|
|
111
|
+
if (tokens.length === 0) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
const approveInstrs = tokens.flatMap((token) => {
|
|
115
|
+
if (token.id === constants_1.ALPH_TOKEN_ID) {
|
|
116
|
+
return [(0, codec_1.U256Const)(token.amount), codec_1.ApproveAlph];
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const tokenId = (0, codec_1.BytesConst)((0, utils_1.hexToBinUnsafe)(token.id));
|
|
120
|
+
return [tokenId, (0, codec_1.U256Const)(token.amount), codec_1.ApproveToken];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return [
|
|
124
|
+
(0, codec_1.AddressConst)(callerLockupScript),
|
|
125
|
+
...Array.from(Array(tokens.length - 1).keys()).map(() => codec_1.Dup),
|
|
126
|
+
...approveInstrs
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
function bigintToNumeric(value) {
|
|
130
|
+
return value >= 0 ? (0, codec_1.toU256)(value) : (0, codec_1.toI256)(value);
|
|
131
|
+
}
|
|
132
|
+
function strToNumeric(str) {
|
|
133
|
+
const regex = /^-?\d+[ui]?$/;
|
|
134
|
+
if (regex.test(str)) {
|
|
135
|
+
if (str.endsWith('i'))
|
|
136
|
+
return (0, codec_1.toI256)(BigInt(str.slice(0, str.length - 1)));
|
|
137
|
+
if (str.endsWith('u'))
|
|
138
|
+
return (0, codec_1.toU256)(BigInt(str.slice(0, str.length - 1)));
|
|
139
|
+
return bigintToNumeric(BigInt(str));
|
|
140
|
+
}
|
|
141
|
+
throw new Error(`Invalid number: ${str}`);
|
|
142
|
+
}
|
|
143
|
+
function toAddressOpt(str) {
|
|
144
|
+
if (!(0, utils_1.isBase58)(str))
|
|
145
|
+
return undefined;
|
|
146
|
+
try {
|
|
147
|
+
return lockup_script_codec_1.lockupScriptCodec.decode((0, utils_1.base58ToBytes)(str));
|
|
148
|
+
}
|
|
149
|
+
catch (_) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function genArgs(args) {
|
|
154
|
+
return args.flatMap((arg) => {
|
|
155
|
+
if (typeof arg === 'boolean')
|
|
156
|
+
return arg ? [codec_1.ConstTrue] : [codec_1.ConstFalse];
|
|
157
|
+
if (typeof arg === 'bigint')
|
|
158
|
+
return bigintToNumeric(arg);
|
|
159
|
+
if (typeof arg === 'string') {
|
|
160
|
+
if ((0, utils_1.isHexString)(arg))
|
|
161
|
+
return [(0, codec_1.BytesConst)((0, utils_1.hexToBinUnsafe)(arg))];
|
|
162
|
+
const addressOpt = toAddressOpt(arg);
|
|
163
|
+
if (addressOpt !== undefined)
|
|
164
|
+
return (0, codec_1.AddressConst)(addressOpt);
|
|
165
|
+
return strToNumeric(arg);
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(arg))
|
|
168
|
+
return genArgs(arg);
|
|
169
|
+
if (arg instanceof Map)
|
|
170
|
+
throw new Error(`Map cannot be used as a function argument`);
|
|
171
|
+
if (typeof arg === 'object')
|
|
172
|
+
return genArgs(Object.values(arg));
|
|
173
|
+
throw new Error(`Unknown argument type: ${typeof arg}, arg: ${arg}`);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
exports.genArgs = genArgs;
|
|
177
|
+
function genContractCall(contractAddress, methodIndex, args, retLength) {
|
|
178
|
+
const argInstrs = genArgs(args);
|
|
179
|
+
return [
|
|
180
|
+
...argInstrs,
|
|
181
|
+
(0, codec_1.toU256)(BigInt(argInstrs.length)),
|
|
182
|
+
(0, codec_1.toU256)(BigInt(retLength)),
|
|
183
|
+
(0, codec_1.BytesConst)((0, address_1.contractIdFromAddress)(contractAddress)),
|
|
184
|
+
(0, codec_1.CallExternal)(methodIndex),
|
|
185
|
+
...Array.from(Array(retLength).keys()).map(() => codec_1.Pop)
|
|
186
|
+
];
|
|
187
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare class EventSubscription extends Subscription<node.ContractEvent>
|
|
|
9
9
|
private onEventCountChanged?;
|
|
10
10
|
constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
|
|
11
11
|
currentEventCount(): number;
|
|
12
|
+
private getEvents;
|
|
12
13
|
polling(): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare function subscribeToEvents(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
@@ -53,11 +53,22 @@ class EventSubscription extends utils_1.Subscription {
|
|
|
53
53
|
currentEventCount() {
|
|
54
54
|
return this.fromCount;
|
|
55
55
|
}
|
|
56
|
+
async getEvents(start) {
|
|
57
|
+
try {
|
|
58
|
+
return await web3
|
|
59
|
+
.getCurrentNodeProvider()
|
|
60
|
+
.events.getEventsContractContractaddress(this.contractAddress, { start });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof Error && error.message.includes(`Contract events of ${this.contractAddress} not found`)) {
|
|
64
|
+
return { events: [], nextStart: start };
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
56
69
|
async polling() {
|
|
57
70
|
try {
|
|
58
|
-
const events = await
|
|
59
|
-
start: this.fromCount
|
|
60
|
-
});
|
|
71
|
+
const events = await this.getEvents(this.fromCount);
|
|
61
72
|
if (this.fromCount === events.nextStart) {
|
|
62
73
|
return;
|
|
63
74
|
}
|
|
@@ -31,8 +31,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
31
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.DappTransactionBuilder = void 0;
|
|
34
35
|
__exportStar(require("./ralph"), exports);
|
|
35
36
|
__exportStar(require("./contract"), exports);
|
|
36
37
|
__exportStar(require("./events"), exports);
|
|
37
38
|
__exportStar(require("./script-simulator"), exports);
|
|
38
39
|
__exportStar(require("./deployment"), exports);
|
|
40
|
+
var dapp_tx_builder_1 = require("./dapp-tx-builder");
|
|
41
|
+
Object.defineProperty(exports, "DappTransactionBuilder", { enumerable: true, get: function () { return dapp_tx_builder_1.DappTransactionBuilder; } });
|
|
@@ -91,42 +91,10 @@ function invalidScriptField(tpe, value) {
|
|
|
91
91
|
return Error(`Invalid script field ${value} for type ${tpe}`);
|
|
92
92
|
}
|
|
93
93
|
function encodeScriptFieldI256(value) {
|
|
94
|
-
|
|
95
|
-
case 0n:
|
|
96
|
-
return codec_1.instrCodec.encode(codec_1.I256Const0);
|
|
97
|
-
case 1n:
|
|
98
|
-
return codec_1.instrCodec.encode(codec_1.I256Const1);
|
|
99
|
-
case 2n:
|
|
100
|
-
return codec_1.instrCodec.encode(codec_1.I256Const2);
|
|
101
|
-
case 3n:
|
|
102
|
-
return codec_1.instrCodec.encode(codec_1.I256Const3);
|
|
103
|
-
case 4n:
|
|
104
|
-
return codec_1.instrCodec.encode(codec_1.I256Const4);
|
|
105
|
-
case 5n:
|
|
106
|
-
return codec_1.instrCodec.encode(codec_1.I256Const5);
|
|
107
|
-
case -1n:
|
|
108
|
-
return codec_1.instrCodec.encode(codec_1.I256ConstN1);
|
|
109
|
-
default:
|
|
110
|
-
return codec_1.instrCodec.encode((0, codec_1.I256Const)(value));
|
|
111
|
-
}
|
|
94
|
+
return codec_1.instrCodec.encode((0, codec_1.toI256)(value));
|
|
112
95
|
}
|
|
113
96
|
function encodeScriptFieldU256(value) {
|
|
114
|
-
|
|
115
|
-
case 0n:
|
|
116
|
-
return codec_1.instrCodec.encode(codec_1.U256Const0);
|
|
117
|
-
case 1n:
|
|
118
|
-
return codec_1.instrCodec.encode(codec_1.U256Const1);
|
|
119
|
-
case 2n:
|
|
120
|
-
return codec_1.instrCodec.encode(codec_1.U256Const2);
|
|
121
|
-
case 3n:
|
|
122
|
-
return codec_1.instrCodec.encode(codec_1.U256Const3);
|
|
123
|
-
case 4n:
|
|
124
|
-
return codec_1.instrCodec.encode(codec_1.U256Const4);
|
|
125
|
-
case 5n:
|
|
126
|
-
return codec_1.instrCodec.encode(codec_1.U256Const5);
|
|
127
|
-
default:
|
|
128
|
-
return codec_1.instrCodec.encode((0, codec_1.U256Const)(value));
|
|
129
|
-
}
|
|
97
|
+
return codec_1.instrCodec.encode((0, codec_1.toU256)(value));
|
|
130
98
|
}
|
|
131
99
|
function encodeScriptFieldAsString(tpe, value) {
|
|
132
100
|
return (0, utils_1.binToHex)(encodeScriptField(tpe, value));
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import { HexString } from '../utils';
|
|
1
2
|
import { Transaction } from '../api/api-alephium';
|
|
2
3
|
import { Address } from '../signer';
|
|
3
4
|
export declare function validateExchangeAddress(address: string): void;
|
|
4
5
|
export declare function isALPHTransferTx(tx: Transaction): boolean;
|
|
5
|
-
export
|
|
6
|
+
export interface BaseDepositInfo {
|
|
6
7
|
targetAddress: Address;
|
|
7
8
|
depositAmount: bigint;
|
|
8
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export declare function getALPHDepositInfo(tx: Transaction): BaseDepositInfo[];
|
|
11
|
+
export interface TokenDepositInfo extends BaseDepositInfo {
|
|
12
|
+
tokenId: HexString;
|
|
13
|
+
}
|
|
14
|
+
export interface DepositInfo {
|
|
15
|
+
alph: BaseDepositInfo[];
|
|
16
|
+
tokens: TokenDepositInfo[];
|
|
17
|
+
}
|
|
18
|
+
export declare function getDepositInfo(tx: Transaction): DepositInfo;
|
|
9
19
|
export declare function getSenderAddress(tx: Transaction): Address;
|
|
10
20
|
export declare function getAddressFromUnlockScript(unlockScript: string): Address;
|
|
21
|
+
export declare function isTransferTx(tx: Transaction): boolean;
|