@alephium/web3 2.0.0-beta.2 → 2.0.0-rc.1
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/contract/contract.js +3 -9
- package/dist/src/signer/signer.js +31 -12
- package/dist/src/signer/tx-builder.js +22 -18
- package/dist/src/signer/types.d.ts +4 -6
- package/package.json +1 -1
- package/src/contract/contract.ts +3 -9
- package/src/signer/signer.ts +33 -12
- package/src/signer/tx-builder.ts +22 -18
- package/src/signer/types.ts +6 -8
|
@@ -694,8 +694,8 @@ class ContractFactory {
|
|
|
694
694
|
const result = await signer.signAndSubmitDeployContractTx(signerParams);
|
|
695
695
|
if ('transferTxs' in result) {
|
|
696
696
|
return {
|
|
697
|
-
...result
|
|
698
|
-
contractInstance: this.at(result.
|
|
697
|
+
...result,
|
|
698
|
+
contractInstance: this.at(result.contractAddress)
|
|
699
699
|
};
|
|
700
700
|
}
|
|
701
701
|
else {
|
|
@@ -733,13 +733,7 @@ class ExecutableScript {
|
|
|
733
733
|
}
|
|
734
734
|
async execute(params) {
|
|
735
735
|
const signerParams = await this.script.txParamsForExecution(params);
|
|
736
|
-
|
|
737
|
-
if ('transferTxs' in result) {
|
|
738
|
-
return result.tx;
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
return result;
|
|
742
|
-
}
|
|
736
|
+
return await params.signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
743
737
|
}
|
|
744
738
|
async call(params) {
|
|
745
739
|
const mainFunc = this.script.functions.find((f) => f.name === 'main');
|
|
@@ -85,7 +85,7 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
85
85
|
for (const r of signResult.transferTxs) {
|
|
86
86
|
await this.submitTransaction(r);
|
|
87
87
|
}
|
|
88
|
-
await this.submitTransaction(signResult
|
|
88
|
+
await this.submitTransaction(signResult);
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
91
|
await this.submitTransaction(signResult);
|
|
@@ -98,7 +98,7 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
98
98
|
for (const r of signResult.transferTxs) {
|
|
99
99
|
await this.submitTransaction(r);
|
|
100
100
|
}
|
|
101
|
-
await this.submitTransaction(signResult
|
|
101
|
+
await this.submitTransaction(signResult);
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
104
|
await this.submitTransaction(signResult);
|
|
@@ -111,7 +111,7 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
111
111
|
for (const r of signResult.transferTxs) {
|
|
112
112
|
await this.submitTransaction(r);
|
|
113
113
|
}
|
|
114
|
-
await this.submitTransaction(signResult
|
|
114
|
+
await this.submitTransaction(signResult);
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
await this.submitTransaction(signResult);
|
|
@@ -141,10 +141,16 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
141
141
|
signature: txSignature
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
144
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
145
145
|
return {
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
fromGroup: response.fromGroup,
|
|
147
|
+
toGroup: response.toGroup,
|
|
148
|
+
gasAmount: response.gasAmount,
|
|
149
|
+
gasPrice: response.gasPrice,
|
|
150
|
+
txId: response.txId,
|
|
151
|
+
unsignedTx: response.unsignedTx,
|
|
152
|
+
signature,
|
|
153
|
+
transferTxs
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
else {
|
|
@@ -166,10 +172,17 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
166
172
|
signature: txSignature
|
|
167
173
|
});
|
|
168
174
|
}
|
|
169
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
175
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
170
176
|
return {
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
contractAddress: response.contractAddress,
|
|
178
|
+
contractId: response.contractId,
|
|
179
|
+
gasAmount: response.gasAmount,
|
|
180
|
+
gasPrice: response.gasPrice,
|
|
181
|
+
groupIndex: response.groupIndex,
|
|
182
|
+
unsignedTx: response.unsignedTx,
|
|
183
|
+
txId: response.txId,
|
|
184
|
+
signature,
|
|
185
|
+
transferTxs
|
|
173
186
|
};
|
|
174
187
|
}
|
|
175
188
|
else {
|
|
@@ -191,10 +204,16 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
191
204
|
signature: txSignature
|
|
192
205
|
});
|
|
193
206
|
}
|
|
194
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
207
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
195
208
|
return {
|
|
196
|
-
|
|
197
|
-
|
|
209
|
+
gasAmount: response.gasAmount,
|
|
210
|
+
gasPrice: response.gasPrice,
|
|
211
|
+
groupIndex: response.groupIndex,
|
|
212
|
+
unsignedTx: response.unsignedTx,
|
|
213
|
+
txId: response.txId,
|
|
214
|
+
simulationResult: response.simulationResult,
|
|
215
|
+
signature,
|
|
216
|
+
transferTxs
|
|
198
217
|
};
|
|
199
218
|
}
|
|
200
219
|
else {
|
|
@@ -163,14 +163,16 @@ class TransactionBuilder {
|
|
|
163
163
|
// BuildGrouplessTransferTxResult
|
|
164
164
|
if ('transferTxs' in result) {
|
|
165
165
|
return {
|
|
166
|
+
unsignedTx: result.unsignedTx,
|
|
167
|
+
gasAmount: result.gasAmount,
|
|
168
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
169
|
+
txId: result.txId,
|
|
170
|
+
fromGroup: result.fromGroup,
|
|
171
|
+
toGroup: result.toGroup,
|
|
166
172
|
transferTxs: result.transferTxs.map((r) => ({
|
|
167
173
|
...r,
|
|
168
174
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
169
|
-
}))
|
|
170
|
-
tx: {
|
|
171
|
-
...result,
|
|
172
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
173
|
-
}
|
|
175
|
+
}))
|
|
174
176
|
};
|
|
175
177
|
}
|
|
176
178
|
return {
|
|
@@ -182,16 +184,17 @@ class TransactionBuilder {
|
|
|
182
184
|
if ('transferTxs' in result) {
|
|
183
185
|
const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.contractAddress));
|
|
184
186
|
return {
|
|
187
|
+
groupIndex: result.fromGroup,
|
|
188
|
+
unsignedTx: result.unsignedTx,
|
|
189
|
+
gasAmount: result.gasAmount,
|
|
190
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
191
|
+
txId: result.txId,
|
|
192
|
+
contractAddress: result.contractAddress,
|
|
193
|
+
contractId,
|
|
185
194
|
transferTxs: result.transferTxs.map((r) => ({
|
|
186
195
|
...r,
|
|
187
196
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
188
|
-
}))
|
|
189
|
-
tx: {
|
|
190
|
-
...result,
|
|
191
|
-
groupIndex: result.fromGroup,
|
|
192
|
-
contractId,
|
|
193
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
194
|
-
}
|
|
197
|
+
}))
|
|
195
198
|
};
|
|
196
199
|
}
|
|
197
200
|
const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.contractAddress));
|
|
@@ -205,15 +208,16 @@ class TransactionBuilder {
|
|
|
205
208
|
convertExecuteScriptTxResult(result) {
|
|
206
209
|
if ('transferTxs' in result) {
|
|
207
210
|
return {
|
|
211
|
+
groupIndex: result.fromGroup,
|
|
212
|
+
unsignedTx: result.unsignedTx,
|
|
213
|
+
txId: result.txId,
|
|
214
|
+
gasAmount: result.gasAmount,
|
|
215
|
+
simulationResult: result.simulationResult,
|
|
216
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
208
217
|
transferTxs: result.transferTxs.map((r) => ({
|
|
209
218
|
...r,
|
|
210
219
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
211
|
-
}))
|
|
212
|
-
tx: {
|
|
213
|
-
...result,
|
|
214
|
-
groupIndex: result.fromGroup,
|
|
215
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
216
|
-
}
|
|
220
|
+
}))
|
|
217
221
|
};
|
|
218
222
|
}
|
|
219
223
|
return {
|
|
@@ -82,15 +82,13 @@ export interface SignExecuteScriptTxResult {
|
|
|
82
82
|
gasPrice: Number256;
|
|
83
83
|
simulationResult: SimulationResult;
|
|
84
84
|
}
|
|
85
|
-
export
|
|
85
|
+
export type GrouplessBuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = {
|
|
86
86
|
transferTxs: Omit<SignTransferTxResult, 'signature'>[];
|
|
87
|
-
|
|
88
|
-
}
|
|
87
|
+
} & Omit<T, 'signature'>;
|
|
89
88
|
export type BuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessBuildTxResult<T> | Omit<T, 'signature'>;
|
|
90
|
-
export
|
|
89
|
+
export type GrouplessSignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = {
|
|
91
90
|
transferTxs: SignTransferTxResult[];
|
|
92
|
-
|
|
93
|
-
}
|
|
91
|
+
} & T;
|
|
94
92
|
export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessSignTxResult<T> | T;
|
|
95
93
|
export interface SignUnsignedTxParams {
|
|
96
94
|
signerAddress: string;
|
package/package.json
CHANGED
package/src/contract/contract.ts
CHANGED
|
@@ -1111,8 +1111,8 @@ export abstract class ContractFactory<I extends ContractInstance, F extends Fiel
|
|
|
1111
1111
|
const result = await signer.signAndSubmitDeployContractTx(signerParams)
|
|
1112
1112
|
if ('transferTxs' in result) {
|
|
1113
1113
|
return {
|
|
1114
|
-
...result
|
|
1115
|
-
contractInstance: this.at(result.
|
|
1114
|
+
...result,
|
|
1115
|
+
contractInstance: this.at(result.contractAddress)
|
|
1116
1116
|
}
|
|
1117
1117
|
} else {
|
|
1118
1118
|
return {
|
|
@@ -1160,13 +1160,7 @@ export class ExecutableScript<P extends Fields = Fields, R extends Val | null =
|
|
|
1160
1160
|
|
|
1161
1161
|
async execute(params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult> {
|
|
1162
1162
|
const signerParams = await this.script.txParamsForExecution(params)
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if ('transferTxs' in result) {
|
|
1166
|
-
return result.tx
|
|
1167
|
-
} else {
|
|
1168
|
-
return result
|
|
1169
|
-
}
|
|
1163
|
+
return await params.signer.signAndSubmitExecuteScriptTx(signerParams)
|
|
1170
1164
|
}
|
|
1171
1165
|
|
|
1172
1166
|
async call(params: CallScriptParams<P>): Promise<CallScriptResult<R>> {
|
package/src/signer/signer.ts
CHANGED
|
@@ -113,7 +113,7 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
113
113
|
await this.submitTransaction(r)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
await this.submitTransaction(signResult
|
|
116
|
+
await this.submitTransaction(signResult)
|
|
117
117
|
} else {
|
|
118
118
|
await this.submitTransaction(signResult)
|
|
119
119
|
}
|
|
@@ -131,7 +131,7 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
131
131
|
await this.submitTransaction(r)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
await this.submitTransaction(signResult
|
|
134
|
+
await this.submitTransaction(signResult)
|
|
135
135
|
} else {
|
|
136
136
|
await this.submitTransaction(signResult)
|
|
137
137
|
}
|
|
@@ -149,7 +149,7 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
149
149
|
await this.submitTransaction(r)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
await this.submitTransaction(signResult
|
|
152
|
+
await this.submitTransaction(signResult)
|
|
153
153
|
} else {
|
|
154
154
|
await this.submitTransaction(signResult)
|
|
155
155
|
}
|
|
@@ -184,10 +184,16 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
184
184
|
})
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
187
|
+
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
188
188
|
return {
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
fromGroup: response.fromGroup,
|
|
190
|
+
toGroup: response.toGroup,
|
|
191
|
+
gasAmount: response.gasAmount,
|
|
192
|
+
gasPrice: response.gasPrice,
|
|
193
|
+
txId: response.txId,
|
|
194
|
+
unsignedTx: response.unsignedTx,
|
|
195
|
+
signature,
|
|
196
|
+
transferTxs
|
|
191
197
|
}
|
|
192
198
|
} else {
|
|
193
199
|
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
@@ -215,10 +221,18 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
215
221
|
})
|
|
216
222
|
}
|
|
217
223
|
|
|
218
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
224
|
+
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
225
|
+
|
|
219
226
|
return {
|
|
220
|
-
|
|
221
|
-
|
|
227
|
+
contractAddress: response.contractAddress,
|
|
228
|
+
contractId: response.contractId,
|
|
229
|
+
gasAmount: response.gasAmount,
|
|
230
|
+
gasPrice: response.gasPrice,
|
|
231
|
+
groupIndex: response.groupIndex,
|
|
232
|
+
unsignedTx: response.unsignedTx,
|
|
233
|
+
txId: response.txId,
|
|
234
|
+
signature,
|
|
235
|
+
transferTxs
|
|
222
236
|
}
|
|
223
237
|
} else {
|
|
224
238
|
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
@@ -246,10 +260,17 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
246
260
|
})
|
|
247
261
|
}
|
|
248
262
|
|
|
249
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
263
|
+
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
264
|
+
|
|
250
265
|
return {
|
|
251
|
-
|
|
252
|
-
|
|
266
|
+
gasAmount: response.gasAmount,
|
|
267
|
+
gasPrice: response.gasPrice,
|
|
268
|
+
groupIndex: response.groupIndex,
|
|
269
|
+
unsignedTx: response.unsignedTx,
|
|
270
|
+
txId: response.txId,
|
|
271
|
+
simulationResult: response.simulationResult,
|
|
272
|
+
signature,
|
|
273
|
+
transferTxs
|
|
253
274
|
}
|
|
254
275
|
} else {
|
|
255
276
|
const signature = await this.signRaw(params.signerAddress, response.txId)
|
package/src/signer/tx-builder.ts
CHANGED
|
@@ -222,14 +222,16 @@ export abstract class TransactionBuilder {
|
|
|
222
222
|
// BuildGrouplessTransferTxResult
|
|
223
223
|
if ('transferTxs' in result) {
|
|
224
224
|
return {
|
|
225
|
+
unsignedTx: result.unsignedTx,
|
|
226
|
+
gasAmount: result.gasAmount,
|
|
227
|
+
gasPrice: fromApiNumber256(result.gasPrice),
|
|
228
|
+
txId: result.txId,
|
|
229
|
+
fromGroup: result.fromGroup,
|
|
230
|
+
toGroup: result.toGroup,
|
|
225
231
|
transferTxs: result.transferTxs.map((r) => ({
|
|
226
232
|
...r,
|
|
227
233
|
gasPrice: fromApiNumber256(r.gasPrice)
|
|
228
|
-
}))
|
|
229
|
-
tx: {
|
|
230
|
-
...result,
|
|
231
|
-
gasPrice: fromApiNumber256(result.gasPrice)
|
|
232
|
-
}
|
|
234
|
+
}))
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
|
|
@@ -245,16 +247,17 @@ export abstract class TransactionBuilder {
|
|
|
245
247
|
if ('transferTxs' in result) {
|
|
246
248
|
const contractId = binToHex(contractIdFromAddress(result.contractAddress))
|
|
247
249
|
return {
|
|
250
|
+
groupIndex: result.fromGroup,
|
|
251
|
+
unsignedTx: result.unsignedTx,
|
|
252
|
+
gasAmount: result.gasAmount,
|
|
253
|
+
gasPrice: fromApiNumber256(result.gasPrice),
|
|
254
|
+
txId: result.txId,
|
|
255
|
+
contractAddress: result.contractAddress,
|
|
256
|
+
contractId,
|
|
248
257
|
transferTxs: result.transferTxs.map((r) => ({
|
|
249
258
|
...r,
|
|
250
259
|
gasPrice: fromApiNumber256(r.gasPrice)
|
|
251
|
-
}))
|
|
252
|
-
tx: {
|
|
253
|
-
...result,
|
|
254
|
-
groupIndex: result.fromGroup,
|
|
255
|
-
contractId,
|
|
256
|
-
gasPrice: fromApiNumber256(result.gasPrice)
|
|
257
|
-
}
|
|
260
|
+
}))
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
|
|
@@ -272,15 +275,16 @@ export abstract class TransactionBuilder {
|
|
|
272
275
|
): BuildTxResult<SignExecuteScriptTxResult> {
|
|
273
276
|
if ('transferTxs' in result) {
|
|
274
277
|
return {
|
|
278
|
+
groupIndex: result.fromGroup,
|
|
279
|
+
unsignedTx: result.unsignedTx,
|
|
280
|
+
txId: result.txId,
|
|
281
|
+
gasAmount: result.gasAmount,
|
|
282
|
+
simulationResult: result.simulationResult,
|
|
283
|
+
gasPrice: fromApiNumber256(result.gasPrice),
|
|
275
284
|
transferTxs: result.transferTxs.map((r) => ({
|
|
276
285
|
...r,
|
|
277
286
|
gasPrice: fromApiNumber256(r.gasPrice)
|
|
278
|
-
}))
|
|
279
|
-
tx: {
|
|
280
|
-
...result,
|
|
281
|
-
groupIndex: result.fromGroup,
|
|
282
|
-
gasPrice: fromApiNumber256(result.gasPrice)
|
|
283
|
-
}
|
|
287
|
+
}))
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
290
|
|
package/src/signer/types.ts
CHANGED
|
@@ -126,23 +126,21 @@ assertType<
|
|
|
126
126
|
>
|
|
127
127
|
>()
|
|
128
128
|
|
|
129
|
-
export
|
|
129
|
+
export type GrouplessBuildTxResult<
|
|
130
130
|
T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult
|
|
131
|
-
> {
|
|
131
|
+
> = {
|
|
132
132
|
transferTxs: Omit<SignTransferTxResult, 'signature'>[]
|
|
133
|
-
|
|
134
|
-
}
|
|
133
|
+
} & Omit<T, 'signature'>
|
|
135
134
|
|
|
136
135
|
export type BuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> =
|
|
137
136
|
| GrouplessBuildTxResult<T>
|
|
138
137
|
| Omit<T, 'signature'>
|
|
139
138
|
|
|
140
|
-
export
|
|
139
|
+
export type GrouplessSignTxResult<
|
|
141
140
|
T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult
|
|
142
|
-
> {
|
|
141
|
+
> = {
|
|
143
142
|
transferTxs: SignTransferTxResult[]
|
|
144
|
-
|
|
145
|
-
}
|
|
143
|
+
} & T
|
|
146
144
|
|
|
147
145
|
export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> =
|
|
148
146
|
| GrouplessSignTxResult<T>
|