@alephium/web3 1.12.0-beta.0 → 1.12.0-danube.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.
@@ -63,7 +63,7 @@ import {
63
63
  groupOfAddress,
64
64
  addressFromContractId,
65
65
  subContractId,
66
- isGrouplessAddressWithoutGroupIndex,
66
+ isGrouplessAddressWithoutGroupIndex
67
67
  } from '../address'
68
68
  import { getCurrentNodeProvider } from '../global'
69
69
  import { EventSubscribeOptions, EventSubscription, subscribeToEvents } from './events'
@@ -96,6 +96,7 @@ import {
96
96
  BytesConst
97
97
  } from '../codec'
98
98
  import { TraceableError } from '../error'
99
+ import { SimulationResult } from '../api/api-alephium'
99
100
 
100
101
  const crypto = new WebCrypto()
101
102
 
@@ -487,16 +488,17 @@ export class Contract extends Artifact {
487
488
  blockHash: params.blockHash,
488
489
  blockTimeStamp: params.blockTimeStamp,
489
490
  txId: params.txId,
490
- address: params.address,
491
+ address: params.contractAddress,
491
492
  callerContractAddress: params.callerContractAddress,
492
493
  bytecode: this.isInlineFunc(methodIndex) ? this.getByteCodeForTesting() : this.bytecodeDebug,
493
494
  initialImmFields: immFields,
494
495
  initialMutFields: mutFields,
495
496
  initialAsset: typeof params.initialAsset !== 'undefined' ? toApiAsset(params.initialAsset) : undefined,
496
497
  methodIndex,
497
- args: this.toApiArgs(funcName, params.testArgs),
498
+ args: this.toApiArgs(funcName, params.args),
498
499
  existingContracts: this.toApiContractStates(params.existingContracts),
499
- inputAssets: toApiInputAssets(params.inputAssets)
500
+ inputAssets: toApiInputAssets(params.inputAssets),
501
+ dustAmount: params.dustAmount?.toString()
500
502
  }
501
503
  }
502
504
 
@@ -607,16 +609,14 @@ export class Contract extends Artifact {
607
609
  params.exposePrivateFunctions ?? false
608
610
  )
609
611
  const selectedAccount = await signer.getSelectedAccount()
610
- let signerAddress = selectedAccount.address
611
- if (isGrouplessAddressWithoutGroupIndex(selectedAccount.address)) {
612
+ if (selectedAccount.keyType === 'gl-secp256k1') {
612
613
  if (group === undefined) {
613
614
  throw new Error('Groupless address requires explicit group number for contract deployment')
614
615
  }
615
- signerAddress = `${selectedAccount.address}:${group}`
616
616
  }
617
617
 
618
618
  const signerParams: SignDeployContractTxParams = {
619
- signerAddress,
619
+ signerAddress: selectedAccount.address,
620
620
  signerKeyType: selectedAccount.keyType,
621
621
  bytecode: bytecode,
622
622
  initialAttoAlphAmount: params?.initialAttoAlphAmount,
@@ -624,7 +624,8 @@ export class Contract extends Artifact {
624
624
  issueTokenTo: params?.issueTokenTo,
625
625
  initialTokenAmounts: params?.initialTokenAmounts,
626
626
  gasAmount: params?.gasAmount,
627
- gasPrice: params?.gasPrice
627
+ gasPrice: params?.gasPrice,
628
+ group: group
628
629
  }
629
630
  return signerParams
630
631
  }
@@ -790,11 +791,8 @@ export class Script extends Artifact {
790
791
  return JSON.stringify(object, null, 2)
791
792
  }
792
793
 
793
- async txParamsForExecution<P extends Fields>(
794
- signer: SignerProvider,
795
- params: ExecuteScriptParams<P>
796
- ): Promise<SignExecuteScriptTxParams> {
797
- const selectedAccount = await signer.getSelectedAccount()
794
+ async txParamsForExecution<P extends Fields>(params: ExecuteScriptParams<P>): Promise<SignExecuteScriptTxParams> {
795
+ const selectedAccount = await params.signer.getSelectedAccount()
798
796
  const signerParams: SignExecuteScriptTxParams = {
799
797
  signerAddress: selectedAccount.address,
800
798
  signerKeyType: selectedAccount.keyType,
@@ -981,7 +979,7 @@ export interface TestContractParams<
981
979
  M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>
982
980
  > {
983
981
  group?: number // default 0
984
- address?: string
982
+ contractAddress?: string
985
983
  callerContractAddress?: string
986
984
  blockHash?: string
987
985
  blockTimeStamp?: number
@@ -989,9 +987,10 @@ export interface TestContractParams<
989
987
  initialFields: F
990
988
  initialMaps?: M
991
989
  initialAsset?: Asset // default 1 ALPH
992
- testArgs: A
990
+ args: A
993
991
  existingContracts?: ContractStateWithMaps[] // default no existing contracts
994
992
  inputAssets?: InputAsset[] // default no input asserts
993
+ dustAmount?: Number256
995
994
  }
996
995
 
997
996
  export interface ContractEvent<T extends Fields = Fields> {
@@ -1071,6 +1070,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
1071
1070
  gasAmount?: number
1072
1071
  gasPrice?: Number256
1073
1072
  exposePrivateFunctions?: boolean
1073
+ group?: number
1074
1074
  }
1075
1075
  assertType<
1076
1076
  Eq<
@@ -1108,9 +1108,16 @@ export abstract class ContractFactory<I extends ContractInstance, F extends Fiel
1108
1108
  group
1109
1109
  )
1110
1110
  const result = await signer.signAndSubmitDeployContractTx(signerParams)
1111
- return {
1112
- ...result,
1113
- contractInstance: this.at(result.contractAddress)
1111
+ if ('transferTxs' in result) {
1112
+ return {
1113
+ ...result.tx,
1114
+ contractInstance: this.at(result.tx.contractAddress)
1115
+ }
1116
+ } else {
1117
+ return {
1118
+ ...result,
1119
+ contractInstance: this.at(result.contractAddress)
1120
+ }
1114
1121
  }
1115
1122
  }
1116
1123
 
@@ -1150,9 +1157,15 @@ export class ExecutableScript<P extends Fields = Fields, R extends Val | null =
1150
1157
  this.getContractByCodeHash = getContractByCodeHash
1151
1158
  }
1152
1159
 
1153
- async execute(signer: SignerProvider, params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult> {
1154
- const signerParams = await this.script.txParamsForExecution(signer, params)
1155
- return await signer.signAndSubmitExecuteScriptTx(signerParams)
1160
+ async execute(params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult> {
1161
+ const signerParams = await this.script.txParamsForExecution(params)
1162
+ const result = await params.signer.signAndSubmitExecuteScriptTx(signerParams)
1163
+
1164
+ if ('transferTxs' in result) {
1165
+ return result.tx
1166
+ } else {
1167
+ return result
1168
+ }
1156
1169
  }
1157
1170
 
1158
1171
  async call(params: CallScriptParams<P>): Promise<CallScriptResult<R>> {
@@ -1177,6 +1190,7 @@ export class ExecutableScript<P extends Fields = Fields, R extends Val | null =
1177
1190
 
1178
1191
  export interface ExecuteScriptParams<P extends Fields = Fields> {
1179
1192
  initialFields: P
1193
+ signer: SignerProvider
1180
1194
  attoAlphAmount?: Number256
1181
1195
  tokens?: Token[]
1182
1196
  gasAmount?: number
@@ -1190,6 +1204,7 @@ export interface ExecuteScriptResult {
1190
1204
  signature: string
1191
1205
  gasAmount: number
1192
1206
  gasPrice: Number256
1207
+ simulationResult: SimulationResult
1193
1208
  }
1194
1209
 
1195
1210
  export interface CallScriptParams<P extends Fields = Fields> {
@@ -1456,7 +1471,7 @@ function getTestExistingContracts(
1456
1471
  selfContract: Contract,
1457
1472
  selfContractId: string,
1458
1473
  group: number,
1459
- params: Optional<TestContractParams, 'testArgs' | 'initialFields'>,
1474
+ params: Optional<TestContractParams, 'args' | 'initialFields'>,
1460
1475
  getContractByCodeHash: (codeHash: string) => Contract
1461
1476
  ): ContractState[] {
1462
1477
  const selfMaps = params.initialMaps ?? {}
@@ -1507,7 +1522,7 @@ function getNewCreatedContractExceptMaps(
1507
1522
 
1508
1523
  export function extractMapsFromApiResult(
1509
1524
  selfAddress: string,
1510
- params: Optional<TestContractParams, 'testArgs' | 'initialFields'>,
1525
+ params: Optional<TestContractParams, 'args' | 'initialFields'>,
1511
1526
  group: number,
1512
1527
  apiResult: node.TestContractResult,
1513
1528
  getContractByCodeHash: (codeHash: string) => Contract
@@ -1540,22 +1555,23 @@ export async function testMethod<
1540
1555
  >(
1541
1556
  factory: ContractFactory<I, F>,
1542
1557
  methodName: string,
1543
- params: Optional<TestContractParams<F, A, M>, 'testArgs' | 'initialFields'>,
1558
+ params: Optional<TestContractParams<F, A, M>, 'args' | 'initialFields'>,
1544
1559
  getContractByCodeHash: (codeHash: string) => Contract
1545
1560
  ): Promise<TestContractResult<R, M>> {
1546
1561
  const txId = params?.txId ?? randomTxId()
1547
1562
  const selfContract = factory.contract
1548
- const selfAddress = params.address ?? addressFromContractId(binToHex(crypto.getRandomValues(new Uint8Array(32))))
1563
+ const selfAddress =
1564
+ params.contractAddress ?? addressFromContractId(binToHex(crypto.getRandomValues(new Uint8Array(32))))
1549
1565
  const selfContractId = binToHex(contractIdFromAddress(selfAddress))
1550
1566
  const group = params.group ?? 0
1551
1567
  const existingContracts = getTestExistingContracts(selfContract, selfContractId, group, params, getContractByCodeHash)
1552
1568
 
1553
1569
  const apiParams = selfContract.toApiTestContractParams(methodName, {
1554
1570
  ...params,
1555
- address: selfAddress,
1571
+ contractAddress: selfAddress,
1556
1572
  txId: txId,
1557
1573
  initialFields: addStdIdToFields(selfContract, params.initialFields ?? {}),
1558
- testArgs: params.testArgs === undefined ? {} : params.testArgs,
1574
+ args: params.args === undefined ? {} : params.args,
1559
1575
  existingContracts
1560
1576
  })
1561
1577
  const apiResult = await getCurrentNodeProvider().contracts.postContractsTestContract(apiParams)
@@ -1955,7 +1971,7 @@ export async function signExecuteMethod<I extends ContractInstance, F extends Fi
1955
1971
  gasPrice: params.gasPrice
1956
1972
  }
1957
1973
 
1958
- const result = await signer.signAndSubmitExecuteScriptTx(signerParams)
1974
+ const result = (await signer.signAndSubmitExecuteScriptTx(signerParams)) as SignExecuteScriptTxResult
1959
1975
  if (isContractDebugMessageEnabled() && isDevnet) {
1960
1976
  await printDebugMessagesFromTx(result.txId, signer.nodeProvider)
1961
1977
  }
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
16
16
  along with the library. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
+ import { SimulationResult } from '../api/api-alephium'
19
20
  import { ContractInstance } from './contract'
20
21
 
21
22
  export interface ExecutionResult {
@@ -37,4 +38,5 @@ export interface DeployContractExecutionResult<I extends ContractInstance = Cont
37
38
 
38
39
  export interface RunScriptResult extends ExecutionResult {
39
40
  groupIndex: number
41
+ simulationResult: SimulationResult
40
42
  }
@@ -41,7 +41,9 @@ import {
41
41
  KeyType,
42
42
  MessageHasher,
43
43
  SignChainedTxParams,
44
- SignChainedTxResult
44
+ SignChainedTxResult,
45
+ BuildTxResult,
46
+ SignTxResult
45
47
  } from './types'
46
48
  import { TransactionBuilder } from './tx-builder'
47
49
  import { addressFromPublicKey, groupOfAddress } from '../address'
@@ -65,9 +67,13 @@ export abstract class SignerProvider {
65
67
  }
66
68
  }
67
69
 
68
- abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>
69
- abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>
70
- abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>
70
+ abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>
71
+ abstract signAndSubmitDeployContractTx(
72
+ params: SignDeployContractTxParams
73
+ ): Promise<SignTxResult<SignDeployContractTxResult>>
74
+ abstract signAndSubmitExecuteScriptTx(
75
+ params: SignExecuteScriptTxParams
76
+ ): Promise<SignTxResult<SignExecuteScriptTxResult>>
71
77
  abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>
72
78
  abstract signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>
73
79
 
@@ -99,19 +105,55 @@ export abstract class SignerProviderSimple extends SignerProvider {
99
105
  return this.nodeProvider.transactions.postTransactionsSubmit(data)
100
106
  }
101
107
 
102
- async signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult> {
108
+ async signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>> {
103
109
  const signResult = await this.signTransferTx(params)
104
- await this.submitTransaction(signResult)
110
+
111
+ if ('transferTxs' in signResult) {
112
+ for (const r of signResult.transferTxs) {
113
+ await this.submitTransaction(r)
114
+ }
115
+
116
+ await this.submitTransaction(signResult.tx)
117
+ } else {
118
+ await this.submitTransaction(signResult)
119
+ }
120
+
105
121
  return signResult
106
122
  }
107
- async signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult> {
123
+
124
+ async signAndSubmitDeployContractTx(
125
+ params: SignDeployContractTxParams
126
+ ): Promise<SignTxResult<SignDeployContractTxResult>> {
108
127
  const signResult = await this.signDeployContractTx(params)
109
- await this.submitTransaction(signResult)
128
+
129
+ if ('transferTxs' in signResult) {
130
+ for (const r of signResult.transferTxs) {
131
+ await this.submitTransaction(r)
132
+ }
133
+
134
+ await this.submitTransaction(signResult.tx)
135
+ } else {
136
+ await this.submitTransaction(signResult)
137
+ }
138
+
110
139
  return signResult
111
140
  }
112
- async signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult> {
141
+
142
+ async signAndSubmitExecuteScriptTx(
143
+ params: SignExecuteScriptTxParams
144
+ ): Promise<SignTxResult<SignExecuteScriptTxResult>> {
113
145
  const signResult = await this.signExecuteScriptTx(params)
114
- await this.submitTransaction(signResult)
146
+
147
+ if ('transferTxs' in signResult) {
148
+ for (const r of signResult.transferTxs) {
149
+ await this.submitTransaction(r)
150
+ }
151
+
152
+ await this.submitTransaction(signResult.tx)
153
+ } else {
154
+ await this.submitTransaction(signResult)
155
+ }
156
+
115
157
  return signResult
116
158
  }
117
159
  async signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult> {
@@ -129,41 +171,93 @@ export abstract class SignerProviderSimple extends SignerProvider {
129
171
 
130
172
  protected abstract getPublicKey(address: string): Promise<string>
131
173
 
132
- async signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult> {
174
+ async signTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>> {
133
175
  const response = await this.buildTransferTx(params)
134
- const signature = await this.signRaw(params.signerAddress, response.txId)
135
- return { signature, ...response }
176
+
177
+ if ('transferTxs' in response) {
178
+ const transferTxs: SignTransferTxResult[] = []
179
+ for (let i = 0; i < response.transferTxs.length; i++) {
180
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId)
181
+ transferTxs.push({
182
+ ...response.transferTxs[i],
183
+ signature: txSignature
184
+ })
185
+ }
186
+
187
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId)
188
+ return {
189
+ transferTxs,
190
+ tx: { ...response.tx, signature }
191
+ }
192
+ } else {
193
+ const signature = await this.signRaw(params.signerAddress, response.txId)
194
+ return { signature, ...response }
195
+ }
136
196
  }
137
197
 
138
- async buildTransferTx(params: SignTransferTxParams): Promise<Omit<SignTransferTxResult, 'signature'>> {
198
+ async buildTransferTx(params: SignTransferTxParams): Promise<BuildTxResult<SignTransferTxResult>> {
139
199
  return TransactionBuilder.from(this.nodeProvider).buildTransferTx(
140
200
  params,
141
201
  await this.getPublicKey(params.signerAddress)
142
202
  )
143
203
  }
144
204
 
145
- async signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult> {
205
+ async signDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>> {
146
206
  const response = await this.buildDeployContractTx(params)
147
- const signature = await this.signRaw(params.signerAddress, response.txId)
148
- return { signature, ...response }
207
+
208
+ if ('transferTxs' in response) {
209
+ const transferTxs: SignTransferTxResult[] = []
210
+ for (let i = 0; i < response.transferTxs.length; i++) {
211
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId)
212
+ transferTxs.push({
213
+ ...response.transferTxs[i],
214
+ signature: txSignature
215
+ })
216
+ }
217
+
218
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId)
219
+ return {
220
+ transferTxs,
221
+ tx: { ...response.tx, signature }
222
+ }
223
+ } else {
224
+ const signature = await this.signRaw(params.signerAddress, response.txId)
225
+ return { signature, ...response }
226
+ }
149
227
  }
150
228
 
151
- async buildDeployContractTx(
152
- params: SignDeployContractTxParams
153
- ): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
229
+ async buildDeployContractTx(params: SignDeployContractTxParams): Promise<BuildTxResult<SignDeployContractTxResult>> {
154
230
  return TransactionBuilder.from(this.nodeProvider).buildDeployContractTx(
155
231
  params,
156
232
  await this.getPublicKey(params.signerAddress)
157
233
  )
158
234
  }
159
235
 
160
- async signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult> {
236
+ async signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>> {
161
237
  const response = await this.buildExecuteScriptTx(params)
162
- const signature = await this.signRaw(params.signerAddress, response.txId)
163
- return { signature, ...response }
238
+
239
+ if ('transferTxs' in response) {
240
+ const transferTxs: SignTransferTxResult[] = []
241
+ for (let i = 0; i < response.transferTxs.length; i++) {
242
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId)
243
+ transferTxs.push({
244
+ ...response.transferTxs[i],
245
+ signature: txSignature
246
+ })
247
+ }
248
+
249
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId)
250
+ return {
251
+ transferTxs,
252
+ tx: { ...response.tx, signature }
253
+ }
254
+ } else {
255
+ const signature = await this.signRaw(params.signerAddress, response.txId)
256
+ return { signature, ...response }
257
+ }
164
258
  }
165
259
 
166
- async buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
260
+ async buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<BuildTxResult<SignExecuteScriptTxResult>> {
167
261
  return TransactionBuilder.from(this.nodeProvider).buildExecuteScriptTx(
168
262
  params,
169
263
  await this.getPublicKey(params.signerAddress)
@@ -35,15 +35,18 @@ import {
35
35
  SignTransferTxResult,
36
36
  SignUnsignedTxParams,
37
37
  SignUnsignedTxResult,
38
- SignGrouplessTransferTxParams,
39
- SignGrouplessDeployContractTxParams,
40
- SignTransferChainedTxResult,
41
- SignGrouplessExecuteScriptTxParams
38
+ BuildTxResult,
39
+ GrouplessBuildTxResult
42
40
  } from './types'
43
41
  import { unsignedTxCodec } from '../codec'
44
42
  import { groupIndexOfTransaction } from '../transaction'
45
43
  import { blakeHash } from '../codec/hash'
46
- import { BuildDeployContractTxResult, BuildChainedTx, BuildExecuteScriptTxResult } from '../api/api-alephium'
44
+ import {
45
+ BuildDeployContractTxResult,
46
+ BuildChainedTx,
47
+ BuildExecuteScriptTxResult,
48
+ BuildTransferTxResult
49
+ } from '../api/api-alephium'
47
50
 
48
51
  export abstract class TransactionBuilder {
49
52
  abstract get nodeProvider(): NodeProvider
@@ -67,10 +70,7 @@ export abstract class TransactionBuilder {
67
70
  }
68
71
  }
69
72
 
70
- async buildTransferTx(
71
- params: SignTransferTxParams,
72
- publicKey: string
73
- ): Promise<Omit<SignTransferTxResult, 'signature'>> {
73
+ async buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<BuildTxResult<SignTransferTxResult>> {
74
74
  const data = this.buildTransferTxParams(params, publicKey)
75
75
  const response = await this.nodeProvider.transactions.postTransactionsBuild(data)
76
76
  return this.convertTransferTxResult(response)
@@ -79,7 +79,7 @@ export abstract class TransactionBuilder {
79
79
  async buildDeployContractTx(
80
80
  params: SignDeployContractTxParams,
81
81
  publicKey: string
82
- ): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
82
+ ): Promise<BuildTxResult<SignDeployContractTxResult>> {
83
83
  const data = this.buildDeployContractTxParams(params, publicKey)
84
84
  const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
85
85
  return this.convertDeployContractTxResult(response)
@@ -88,7 +88,7 @@ export abstract class TransactionBuilder {
88
88
  async buildExecuteScriptTx(
89
89
  params: SignExecuteScriptTxParams,
90
90
  publicKey: string
91
- ): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
91
+ ): Promise<BuildTxResult<SignExecuteScriptTxResult>> {
92
92
  const data = this.buildExecuteScriptTxParams(params, publicKey)
93
93
  const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data)
94
94
  return this.convertExecuteScriptTxResult(response)
@@ -130,9 +130,9 @@ export abstract class TransactionBuilder {
130
130
  const buildResultType = buildResult.type
131
131
  switch (buildResultType) {
132
132
  case 'Transfer': {
133
- const buildTransferTxResult = buildResult.value
133
+ const buildTransferTxResult = buildResult.value as BuildTransferTxResult
134
134
  return {
135
- ...this.convertTransferTxResult(buildTransferTxResult),
135
+ ...(this.convertTransferTxResult(buildTransferTxResult) as Omit<SignTransferTxResult, 'signature'>),
136
136
  type: buildResultType
137
137
  }
138
138
  }
@@ -158,51 +158,6 @@ export abstract class TransactionBuilder {
158
158
  return results
159
159
  }
160
160
 
161
- async buildGrouplessTransferTx(
162
- params: SignGrouplessTransferTxParams
163
- ): Promise<Omit<SignChainedTxResult, 'signature'>[]> {
164
- const data = this.buildGrouplessTransferTxParams(params)
165
- const response = await this.nodeProvider.groupless.postGrouplessTransfer(data)
166
- return response.map((result) => {
167
- return {
168
- ...this.convertTransferTxResult(result),
169
- type: 'Transfer' as const
170
- }
171
- })
172
- }
173
-
174
- async buildGrouplessDeployContractTx(
175
- params: SignGrouplessDeployContractTxParams
176
- ): Promise<Omit<SignChainedTxResult, 'signature'>[]> {
177
- const data = this.buildGrouplessDeployContractTxParams(params)
178
- const response = await this.nodeProvider.groupless.postGrouplessDeployContract(data)
179
- const transferTxs = response.transferTxs.map((result) => ({
180
- ...this.convertTransferTxResult(result),
181
- type: 'Transfer' as const
182
- }))
183
- const deployContractTx = {
184
- ...this.convertDeployContractTxResult(response.deployContractTx),
185
- type: 'DeployContract' as const
186
- }
187
- return [...transferTxs, deployContractTx]
188
- }
189
-
190
- async buildGrouplessExecuteScriptTx(
191
- params: SignGrouplessExecuteScriptTxParams
192
- ): Promise<Omit<SignChainedTxResult, 'signature'>[]> {
193
- const data = this.buildGrouplessExecuteScriptTxParams(params)
194
- const response = await this.nodeProvider.groupless.postGrouplessExecuteScript(data)
195
- const transferTxs = response.transferTxs.map((result) => ({
196
- ...this.convertTransferTxResult(result),
197
- type: 'Transfer' as const
198
- }))
199
- const executeScriptTx = {
200
- ...this.convertExecuteScriptTxResult(response.executeScriptTx),
201
- type: 'ExecuteScript' as const
202
- }
203
- return [...transferTxs, executeScriptTx]
204
- }
205
-
206
161
  static buildUnsignedTx(params: SignUnsignedTxParams): Omit<SignUnsignedTxResult, 'signature'> {
207
162
  const unsignedTxBin = hexToBinUnsafe(params.unsignedTx)
208
163
  const decoded = unsignedTxCodec.decode(unsignedTxBin)
@@ -231,44 +186,6 @@ export abstract class TransactionBuilder {
231
186
  }
232
187
  }
233
188
 
234
- private buildGrouplessTransferTxParams(params: SignGrouplessTransferTxParams): node.BuildGrouplessTransferTx {
235
- return {
236
- fromAddress: params.fromAddress,
237
- destinations: toApiDestinations(params.destinations),
238
- gasPrice: toApiNumber256Optional(params.gasPrice),
239
- targetBlockHash: params.targetBlockHash
240
- }
241
- }
242
-
243
- private buildGrouplessDeployContractTxParams(
244
- params: SignGrouplessDeployContractTxParams
245
- ): node.BuildGrouplessDeployContractTx {
246
- return {
247
- fromAddress: params.fromAddress,
248
- bytecode: params.bytecode,
249
- initialAttoAlphAmount: toApiNumber256Optional(params.initialAttoAlphAmount),
250
- initialTokenAmounts: toApiTokens(params.initialTokenAmounts),
251
- issueTokenAmount: toApiNumber256Optional(params.issueTokenAmount),
252
- issueTokenTo: params.issueTokenTo,
253
- gasPrice: toApiNumber256Optional(params.gasPrice),
254
- targetBlockHash: params.targetBlockHash
255
- }
256
- }
257
-
258
- private buildGrouplessExecuteScriptTxParams(
259
- params: SignGrouplessExecuteScriptTxParams
260
- ): node.BuildGrouplessExecuteScriptTx {
261
- return {
262
- fromAddress: params.fromAddress,
263
- bytecode: params.bytecode,
264
- attoAlphAmount: toApiNumber256Optional(params.attoAlphAmount),
265
- tokens: toApiTokens(params.tokens),
266
- gasPrice: toApiNumber256Optional(params.gasPrice),
267
- targetBlockHash: params.targetBlockHash,
268
- gasEstimationMultiplier: params.gasEstimationMultiplier
269
- }
270
- }
271
-
272
189
  private buildDeployContractTxParams(
273
190
  params: SignDeployContractTxParams,
274
191
  publicKey: string
@@ -301,7 +218,21 @@ export abstract class TransactionBuilder {
301
218
  }
302
219
  }
303
220
 
304
- private convertTransferTxResult(result: node.BuildTransferTxResult): Omit<SignTransferTxResult, 'signature'> {
221
+ private convertTransferTxResult(result: node.BuildTransferTxResult): BuildTxResult<SignTransferTxResult> {
222
+ // BuildGrouplessTransferTxResult
223
+ if ('transferTxs' in result) {
224
+ return {
225
+ transferTxs: result.transferTxs.map((r) => ({
226
+ ...r,
227
+ gasPrice: fromApiNumber256(r.gasPrice)
228
+ })),
229
+ tx: {
230
+ ...result.transferTx,
231
+ gasPrice: fromApiNumber256(result.transferTx.gasPrice)
232
+ }
233
+ }
234
+ }
235
+
305
236
  return {
306
237
  ...result,
307
238
  gasPrice: fromApiNumber256(result.gasPrice)
@@ -310,7 +241,23 @@ export abstract class TransactionBuilder {
310
241
 
311
242
  private convertDeployContractTxResult(
312
243
  result: node.BuildDeployContractTxResult
313
- ): Omit<SignDeployContractTxResult, 'signature'> {
244
+ ): BuildTxResult<SignDeployContractTxResult> {
245
+ if ('transferTxs' in result) {
246
+ const contractId = binToHex(contractIdFromAddress(result.deployContractTx.contractAddress))
247
+ return {
248
+ transferTxs: result.transferTxs.map((r) => ({
249
+ ...r,
250
+ gasPrice: fromApiNumber256(r.gasPrice)
251
+ })),
252
+ tx: {
253
+ ...result.deployContractTx,
254
+ groupIndex: result.deployContractTx.fromGroup,
255
+ contractId,
256
+ gasPrice: fromApiNumber256(result.deployContractTx.gasPrice)
257
+ }
258
+ }
259
+ }
260
+
314
261
  const contractId = binToHex(contractIdFromAddress(result.contractAddress))
315
262
  return {
316
263
  ...result,
@@ -322,7 +269,21 @@ export abstract class TransactionBuilder {
322
269
 
323
270
  private convertExecuteScriptTxResult(
324
271
  result: node.BuildExecuteScriptTxResult
325
- ): Omit<SignExecuteScriptTxResult, 'signature'> {
272
+ ): BuildTxResult<SignExecuteScriptTxResult> {
273
+ if ('transferTxs' in result) {
274
+ return {
275
+ transferTxs: result.transferTxs.map((r) => ({
276
+ ...r,
277
+ gasPrice: fromApiNumber256(r.gasPrice)
278
+ })),
279
+ tx: {
280
+ ...result.executeScriptTx,
281
+ groupIndex: result.executeScriptTx.fromGroup,
282
+ gasPrice: fromApiNumber256(result.executeScriptTx.gasPrice)
283
+ }
284
+ }
285
+ }
286
+
326
287
  return {
327
288
  ...result,
328
289
  groupIndex: result.fromGroup,