@alephium/web3 0.4.0 → 0.5.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/api/api-alephium.d.ts +5 -3
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/types.d.ts +1 -0
- package/dist/src/api/types.js +9 -1
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/dist/src/contract/contract.d.ts +90 -49
- package/dist/src/contract/contract.js +297 -77
- package/dist/src/contract/ralph.js +12 -3
- package/dist/src/signer/tx-builder.js +2 -2
- package/dist/src/signer/types.d.ts +2 -4
- package/dist/src/utils/utils.d.ts +1 -0
- package/dist/src/utils/utils.js +3 -1
- package/package.json +3 -3
- package/src/api/api-alephium.ts +5 -3
- package/src/api/types.ts +8 -0
- package/src/constants.ts +1 -0
- package/src/contract/contract.ts +472 -143
- package/src/contract/ralph.ts +13 -3
- package/src/signer/tx-builder.ts +2 -2
- package/src/signer/types.ts +14 -6
- package/src/utils/utils.ts +4 -1
package/src/contract/ralph.ts
CHANGED
|
@@ -249,8 +249,12 @@ export function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fi
|
|
|
249
249
|
})
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
const
|
|
252
|
+
function encodeFields(fields: Fields, fieldsSig: FieldsSig, mutable: boolean) {
|
|
253
|
+
const fieldIndexes = fieldsSig.isMutable
|
|
254
|
+
.map((_, index) => index)
|
|
255
|
+
.filter((index) => fieldsSig.isMutable[`${index}`] === mutable)
|
|
256
|
+
const fieldsEncoded = fieldIndexes.flatMap((fieldIndex) => {
|
|
257
|
+
const fieldName = fieldsSig.names[`${fieldIndex}`]
|
|
254
258
|
const fieldType = fieldsSig.types[`${fieldIndex}`]
|
|
255
259
|
if (fieldName in fields) {
|
|
256
260
|
const fieldValue = fields[`${fieldName}`]
|
|
@@ -260,7 +264,13 @@ export function buildContractByteCode(bytecode: string, fields: Fields, fieldsSi
|
|
|
260
264
|
}
|
|
261
265
|
})
|
|
262
266
|
const fieldsLength = Buffer.from(encodeI256(BigInt(fieldsEncoded.length))).toString('hex')
|
|
263
|
-
return
|
|
267
|
+
return fieldsLength + fieldsEncoded.map((f) => Buffer.from(f).toString('hex')).join('')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig: FieldsSig): string {
|
|
271
|
+
const encodedImmFields = encodeFields(fields, fieldsSig, false)
|
|
272
|
+
const encodedMutFields = encodeFields(fields, fieldsSig, true)
|
|
273
|
+
return bytecode + encodedImmFields + encodedMutFields
|
|
264
274
|
}
|
|
265
275
|
|
|
266
276
|
enum ApiValType {
|
package/src/signer/tx-builder.ts
CHANGED
|
@@ -85,7 +85,7 @@ export abstract class TransactionBuilder {
|
|
|
85
85
|
}
|
|
86
86
|
const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
|
|
87
87
|
const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress))
|
|
88
|
-
return { ...response, contractId, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
88
|
+
return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
async buildExecuteScriptTx(
|
|
@@ -103,7 +103,7 @@ export abstract class TransactionBuilder {
|
|
|
103
103
|
...rest
|
|
104
104
|
}
|
|
105
105
|
const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data)
|
|
106
|
-
return { ...response, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
106
|
+
return { ...response, groupIndex: response.fromGroup, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
async buildUnsignedTx(params: SignUnsignedTxParams): Promise<Omit<SignUnsignedTxResult, 'signature'>> {
|
package/src/signer/types.ts
CHANGED
|
@@ -73,8 +73,7 @@ export interface SignDeployContractTxParams {
|
|
|
73
73
|
}
|
|
74
74
|
assertType<Eq<keyof SignDeployContractTxParams, keyof TxBuildParams<node.BuildDeployContractTx>>>()
|
|
75
75
|
export interface SignDeployContractTxResult {
|
|
76
|
-
|
|
77
|
-
toGroup: number
|
|
76
|
+
groupIndex: number
|
|
78
77
|
unsignedTx: string
|
|
79
78
|
txId: string
|
|
80
79
|
signature: string
|
|
@@ -83,7 +82,12 @@ export interface SignDeployContractTxResult {
|
|
|
83
82
|
gasAmount: number
|
|
84
83
|
gasPrice: Number256
|
|
85
84
|
}
|
|
86
|
-
assertType<
|
|
85
|
+
assertType<
|
|
86
|
+
Eq<
|
|
87
|
+
Omit<SignDeployContractTxResult, 'groupIndex'>,
|
|
88
|
+
Omit<SignResult<node.BuildDeployContractTxResult> & { contractId: string }, 'fromGroup' | 'toGroup'>
|
|
89
|
+
>
|
|
90
|
+
>()
|
|
87
91
|
|
|
88
92
|
export interface SignExecuteScriptTxParams {
|
|
89
93
|
signerAddress: string
|
|
@@ -95,15 +99,19 @@ export interface SignExecuteScriptTxParams {
|
|
|
95
99
|
}
|
|
96
100
|
assertType<Eq<keyof SignExecuteScriptTxParams, keyof TxBuildParams<node.BuildExecuteScriptTx>>>()
|
|
97
101
|
export interface SignExecuteScriptTxResult {
|
|
98
|
-
|
|
99
|
-
toGroup: number
|
|
102
|
+
groupIndex: number
|
|
100
103
|
unsignedTx: string
|
|
101
104
|
txId: string
|
|
102
105
|
signature: string
|
|
103
106
|
gasAmount: number
|
|
104
107
|
gasPrice: Number256
|
|
105
108
|
}
|
|
106
|
-
assertType<
|
|
109
|
+
assertType<
|
|
110
|
+
Eq<
|
|
111
|
+
Omit<SignExecuteScriptTxResult, 'groupIndex'>,
|
|
112
|
+
Omit<SignResult<node.BuildExecuteScriptTxResult>, 'fromGroup' | 'toGroup'>
|
|
113
|
+
>
|
|
114
|
+
>()
|
|
107
115
|
|
|
108
116
|
export interface SignUnsignedTxParams {
|
|
109
117
|
signerAddress: string
|
package/src/utils/utils.ts
CHANGED
|
@@ -91,7 +91,9 @@ export function groupOfAddress(address: string): number {
|
|
|
91
91
|
} else if (addressType == AddressType.P2SH) {
|
|
92
92
|
return groupOfP2shAddress(addressBody)
|
|
93
93
|
} else {
|
|
94
|
-
|
|
94
|
+
// Contract Address
|
|
95
|
+
const id = contractIdFromAddress(address)
|
|
96
|
+
return id[`${id.length - 1}`]
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
@@ -217,3 +219,4 @@ type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1
|
|
|
217
219
|
export type Eq<X, Y> = _Eq<{ [P in keyof X]: X[P] }, { [P in keyof Y]: Y[P] }>
|
|
218
220
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
219
221
|
export function assertType<T extends true>(): void {}
|
|
222
|
+
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
|