@alephium/web3 0.8.2-test.3 → 0.9.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/package.json +37 -36
- package/src/api/api-alephium.ts +2 -1
- package/src/api/node-provider.ts +41 -25
- package/src/api/types.ts +10 -15
- package/src/contract/contract.ts +63 -40
- package/src/index.ts +1 -0
- package/{dist/scripts/header.js → src/token/index.ts} +2 -1
- package/{dist/src/utils/djb2.js → src/token/nft.ts} +16 -9
- package/std/fungible_token_interface.ral +1 -0
- package/std/nft_collection_interface.ral +24 -3
- package/std/nft_interface.ral +22 -0
- package/dist/alephium-web3.min.js +0 -3
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -12
- package/dist/alephium-web3.min.js.map +0 -1
- package/dist/scripts/check-versions.d.ts +0 -1
- package/dist/scripts/check-versions.js +0 -39
- package/dist/scripts/header.d.ts +0 -0
- package/dist/src/api/api-alephium.d.ts +0 -1716
- package/dist/src/api/api-alephium.js +0 -1284
- package/dist/src/api/api-explorer.d.ts +0 -923
- package/dist/src/api/api-explorer.js +0 -711
- package/dist/src/api/explorer-provider.d.ts +0 -20
- package/dist/src/api/explorer-provider.js +0 -69
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.js +0 -52
- package/dist/src/api/node-provider.d.ts +0 -23
- package/dist/src/api/node-provider.js +0 -93
- package/dist/src/api/types.d.ts +0 -38
- package/dist/src/api/types.js +0 -263
- package/dist/src/api/utils.d.ts +0 -12
- package/dist/src/api/utils.js +0 -59
- package/dist/src/constants.d.ts +0 -6
- package/dist/src/constants.js +0 -26
- package/dist/src/contract/contract.d.ts +0 -293
- package/dist/src/contract/contract.js +0 -1079
- package/dist/src/contract/events.d.ts +0 -11
- package/dist/src/contract/events.js +0 -65
- package/dist/src/contract/index.d.ts +0 -3
- package/dist/src/contract/index.js +0 -36
- package/dist/src/contract/ralph.d.ts +0 -13
- package/dist/src/contract/ralph.js +0 -397
- package/dist/src/global.d.ts +0 -7
- package/dist/src/global.js +0 -54
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +0 -57
- package/dist/src/signer/index.d.ts +0 -3
- package/dist/src/signer/index.js +0 -36
- package/dist/src/signer/signer.d.ts +0 -60
- package/dist/src/signer/signer.js +0 -236
- package/dist/src/signer/tx-builder.d.ts +0 -12
- package/dist/src/signer/tx-builder.js +0 -96
- package/dist/src/signer/types.d.ts +0 -115
- package/dist/src/signer/types.js +0 -30
- package/dist/src/transaction/index.d.ts +0 -2
- package/dist/src/transaction/index.js +0 -35
- package/dist/src/transaction/sign-verify.d.ts +0 -3
- package/dist/src/transaction/sign-verify.js +0 -52
- package/dist/src/transaction/status.d.ts +0 -11
- package/dist/src/transaction/status.js +0 -49
- package/dist/src/utils/address.d.ts +0 -1
- package/dist/src/utils/address.js +0 -42
- package/dist/src/utils/bs58.d.ts +0 -5
- package/dist/src/utils/bs58.js +0 -40
- package/dist/src/utils/djb2.d.ts +0 -1
- package/dist/src/utils/index.d.ts +0 -7
- package/dist/src/utils/index.js +0 -40
- package/dist/src/utils/number.d.ts +0 -18
- package/dist/src/utils/number.fixture.d.ts +0 -12
- package/dist/src/utils/number.fixture.js +0 -189
- package/dist/src/utils/number.js +0 -149
- package/dist/src/utils/sign.d.ts +0 -3
- package/dist/src/utils/sign.js +0 -89
- package/dist/src/utils/subscription.d.ts +0 -21
- package/dist/src/utils/subscription.js +0 -51
- package/dist/src/utils/utils.d.ts +0 -40
- package/dist/src/utils/utils.js +0 -244
- package/jest-config.json +0 -11
package/src/contract/contract.ts
CHANGED
|
@@ -68,6 +68,8 @@ export type Fields = NamedVals
|
|
|
68
68
|
export type Arguments = NamedVals
|
|
69
69
|
export type HexString = string
|
|
70
70
|
|
|
71
|
+
export const StdIdFieldName = '__stdInterfaceId'
|
|
72
|
+
|
|
71
73
|
enum SourceKind {
|
|
72
74
|
Contract = 0,
|
|
73
75
|
Script = 1,
|
|
@@ -667,6 +669,7 @@ export class Contract extends Artifact {
|
|
|
667
669
|
readonly codeHash: string
|
|
668
670
|
readonly fieldsSig: FieldsSig
|
|
669
671
|
readonly eventsSig: EventSig[]
|
|
672
|
+
readonly stdInterfaceId?: HexString
|
|
670
673
|
|
|
671
674
|
readonly bytecodeDebug: string
|
|
672
675
|
readonly codeHashDebug: string
|
|
@@ -680,7 +683,8 @@ export class Contract extends Artifact {
|
|
|
680
683
|
codeHashDebug: string,
|
|
681
684
|
fieldsSig: FieldsSig,
|
|
682
685
|
eventsSig: EventSig[],
|
|
683
|
-
functions: FunctionSig[]
|
|
686
|
+
functions: FunctionSig[],
|
|
687
|
+
stdInterfaceId?: HexString
|
|
684
688
|
) {
|
|
685
689
|
super(version, name, functions)
|
|
686
690
|
this.bytecode = bytecode
|
|
@@ -688,6 +692,7 @@ export class Contract extends Artifact {
|
|
|
688
692
|
this.codeHash = codeHash
|
|
689
693
|
this.fieldsSig = fieldsSig
|
|
690
694
|
this.eventsSig = eventsSig
|
|
695
|
+
this.stdInterfaceId = stdInterfaceId
|
|
691
696
|
|
|
692
697
|
this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch)
|
|
693
698
|
this.codeHashDebug = codeHashDebug
|
|
@@ -715,7 +720,8 @@ export class Contract extends Artifact {
|
|
|
715
720
|
codeHashDebug ? codeHashDebug : artifact.codeHash,
|
|
716
721
|
artifact.fieldsSig,
|
|
717
722
|
artifact.eventsSig,
|
|
718
|
-
artifact.functions
|
|
723
|
+
artifact.functions,
|
|
724
|
+
artifact.stdInterfaceId === null ? undefined : artifact.stdInterfaceId
|
|
719
725
|
)
|
|
720
726
|
return contract
|
|
721
727
|
}
|
|
@@ -730,7 +736,8 @@ export class Contract extends Artifact {
|
|
|
730
736
|
result.codeHashDebug,
|
|
731
737
|
result.fields,
|
|
732
738
|
result.events,
|
|
733
|
-
result.functions
|
|
739
|
+
result.functions,
|
|
740
|
+
result.stdInterfaceId
|
|
734
741
|
)
|
|
735
742
|
}
|
|
736
743
|
|
|
@@ -742,7 +749,7 @@ export class Contract extends Artifact {
|
|
|
742
749
|
}
|
|
743
750
|
|
|
744
751
|
override toString(): string {
|
|
745
|
-
const object = {
|
|
752
|
+
const object: any = {
|
|
746
753
|
version: this.version,
|
|
747
754
|
name: this.name,
|
|
748
755
|
bytecode: this.bytecode,
|
|
@@ -751,6 +758,9 @@ export class Contract extends Artifact {
|
|
|
751
758
|
eventsSig: this.eventsSig,
|
|
752
759
|
functions: this.functions
|
|
753
760
|
}
|
|
761
|
+
if (this.stdInterfaceId !== undefined) {
|
|
762
|
+
object.stdInterfaceId = this.stdInterfaceId
|
|
763
|
+
}
|
|
754
764
|
return JSON.stringify(object, null, 2)
|
|
755
765
|
}
|
|
756
766
|
|
|
@@ -852,16 +862,14 @@ export class Contract extends Artifact {
|
|
|
852
862
|
}
|
|
853
863
|
|
|
854
864
|
static ContractCreatedEventIndex = -1
|
|
855
|
-
static ContractCreatedEvent:
|
|
865
|
+
static ContractCreatedEvent: EventSig = {
|
|
856
866
|
name: 'ContractCreated',
|
|
857
|
-
fieldNames: ['address'],
|
|
858
|
-
fieldTypes: ['Address']
|
|
859
|
-
optionalFieldNames: ['parentAddress'],
|
|
860
|
-
optionalFieldTypes: ['Address']
|
|
867
|
+
fieldNames: ['address', 'parentAddress', 'stdInterfaceId'],
|
|
868
|
+
fieldTypes: ['Address', 'Address', 'ByteVec']
|
|
861
869
|
}
|
|
862
870
|
|
|
863
871
|
static ContractDestroyedEventIndex = -2
|
|
864
|
-
static ContractDestroyedEvent:
|
|
872
|
+
static ContractDestroyedEvent: EventSig = {
|
|
865
873
|
name: 'ContractDestroyed',
|
|
866
874
|
fieldNames: ['address'],
|
|
867
875
|
fieldTypes: ['Address']
|
|
@@ -872,10 +880,10 @@ export class Contract extends Artifact {
|
|
|
872
880
|
let name: string
|
|
873
881
|
|
|
874
882
|
if (event.eventIndex == Contract.ContractCreatedEventIndex) {
|
|
875
|
-
fields =
|
|
883
|
+
fields = toContractCreatedEventFields(fromApiEventFields(event.fields, Contract.ContractCreatedEvent, true))
|
|
876
884
|
name = Contract.ContractCreatedEvent.name
|
|
877
885
|
} else if (event.eventIndex == Contract.ContractDestroyedEventIndex) {
|
|
878
|
-
fields =
|
|
886
|
+
fields = fromApiEventFields(event.fields, Contract.ContractDestroyedEvent, true)
|
|
879
887
|
name = Contract.ContractDestroyedEvent.name
|
|
880
888
|
} else {
|
|
881
889
|
const contract = Project.currentProject.contractByCodeHash(codeHash!)
|
|
@@ -923,7 +931,8 @@ export class Contract extends Artifact {
|
|
|
923
931
|
signer: SignerProvider,
|
|
924
932
|
params: DeployContractParams<P>
|
|
925
933
|
): Promise<SignDeployContractTxParams> {
|
|
926
|
-
const
|
|
934
|
+
const initialFields: Fields = params.initialFields ?? {}
|
|
935
|
+
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields))
|
|
927
936
|
const selectedAccount = await signer.getSelectedAccount()
|
|
928
937
|
const signerParams: SignDeployContractTxParams = {
|
|
929
938
|
signerAddress: selectedAccount.address,
|
|
@@ -1106,18 +1115,8 @@ function fromApiFields(immFields: node.Val[], mutFields: node.Val[], fieldsSig:
|
|
|
1106
1115
|
return fromApiVals(vals, fieldsSig.names, fieldsSig.types)
|
|
1107
1116
|
}
|
|
1108
1117
|
|
|
1109
|
-
function fromApiEventFields(vals: node.Val[], eventSig: node.EventSig): Fields {
|
|
1110
|
-
return fromApiVals(vals, eventSig.fieldNames, eventSig.fieldTypes)
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
function fromApiSystemEventFields(vals: node.Val[], systemEventSig: SystemEventSig): Fields {
|
|
1114
|
-
return fromApiVals(
|
|
1115
|
-
vals,
|
|
1116
|
-
systemEventSig.fieldNames,
|
|
1117
|
-
systemEventSig.fieldTypes,
|
|
1118
|
-
systemEventSig.optionalFieldNames ?? [],
|
|
1119
|
-
systemEventSig.optionalFieldTypes ?? []
|
|
1120
|
-
)
|
|
1118
|
+
function fromApiEventFields(vals: node.Val[], eventSig: node.EventSig, systemEvent = false): Fields {
|
|
1119
|
+
return fromApiVals(vals, eventSig.fieldNames, eventSig.fieldTypes, systemEvent)
|
|
1121
1120
|
}
|
|
1122
1121
|
|
|
1123
1122
|
export interface Asset {
|
|
@@ -1313,7 +1312,10 @@ export abstract class ContractFactory<I, F extends Fields = Fields> {
|
|
|
1313
1312
|
abstract at(address: string): I
|
|
1314
1313
|
|
|
1315
1314
|
async deploy(signer: SignerProvider, deployParams: DeployContractParams<F>): Promise<DeployContractResult<I>> {
|
|
1316
|
-
const signerParams = await this.contract.txParamsForDeployment(signer,
|
|
1315
|
+
const signerParams = await this.contract.txParamsForDeployment(signer, {
|
|
1316
|
+
...deployParams,
|
|
1317
|
+
initialFields: addStdIdToFields(this.contract, deployParams.initialFields)
|
|
1318
|
+
})
|
|
1317
1319
|
const result = await signer.signAndSubmitDeployContractTx(signerParams)
|
|
1318
1320
|
return {
|
|
1319
1321
|
...result,
|
|
@@ -1327,7 +1329,7 @@ export abstract class ContractFactory<I, F extends Fields = Fields> {
|
|
|
1327
1329
|
alphAmount: asset?.alphAmount ?? ONE_ALPH,
|
|
1328
1330
|
tokens: asset?.tokens
|
|
1329
1331
|
}
|
|
1330
|
-
return this.contract.toState(initFields, newAsset, address)
|
|
1332
|
+
return this.contract.toState(addStdIdToFields(this.contract, initFields), newAsset, address)
|
|
1331
1333
|
}
|
|
1332
1334
|
}
|
|
1333
1335
|
|
|
@@ -1374,19 +1376,32 @@ function specialContractAddress(n: number): string {
|
|
|
1374
1376
|
export const CreateContractEventAddress = specialContractAddress(-1)
|
|
1375
1377
|
export const DestroyContractEventAddress = specialContractAddress(-2)
|
|
1376
1378
|
|
|
1377
|
-
export
|
|
1378
|
-
|
|
1379
|
-
|
|
1379
|
+
export type ContractCreatedEventFields = {
|
|
1380
|
+
address: Address
|
|
1381
|
+
parentAddress?: Address
|
|
1382
|
+
stdInterfaceIdGuessed?: HexString
|
|
1380
1383
|
}
|
|
1384
|
+
export type ContractDestroyedEventFields = {
|
|
1385
|
+
address: Address
|
|
1386
|
+
}
|
|
1387
|
+
export type ContractCreatedEvent = ContractEvent<ContractCreatedEventFields>
|
|
1388
|
+
export type ContractDestroyedEvent = ContractEvent<ContractDestroyedEventFields>
|
|
1381
1389
|
|
|
1382
|
-
|
|
1383
|
-
export type ContractDestroyedEvent = ContractEvent<{ address: Address }>
|
|
1384
|
-
|
|
1385
|
-
function decodeSystemEvent(event: node.ContractEvent, systemEventSig: SystemEventSig, eventIndex: number): Fields {
|
|
1390
|
+
function decodeSystemEvent(event: node.ContractEvent, eventSig: EventSig, eventIndex: number): Fields {
|
|
1386
1391
|
if (event.eventIndex !== eventIndex) {
|
|
1387
1392
|
throw new Error(`Invalid event index: ${event.eventIndex}, expected: ${eventIndex}`)
|
|
1388
1393
|
}
|
|
1389
|
-
return
|
|
1394
|
+
return fromApiEventFields(event.fields, eventSig, true)
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
function toContractCreatedEventFields(fields: Fields): ContractCreatedEventFields {
|
|
1398
|
+
const parentAddress = fields['parentAddress'] as string
|
|
1399
|
+
const stdInterfaceId = fields['stdInterfaceId'] as string
|
|
1400
|
+
return {
|
|
1401
|
+
address: fields['address'] as Address,
|
|
1402
|
+
parentAddress: parentAddress === '' ? undefined : (parentAddress as Address),
|
|
1403
|
+
stdInterfaceIdGuessed: stdInterfaceId === '' ? undefined : (stdInterfaceId as HexString)
|
|
1404
|
+
}
|
|
1390
1405
|
}
|
|
1391
1406
|
|
|
1392
1407
|
export function decodeContractCreatedEvent(event: node.ContractEvent): Omit<ContractCreatedEvent, 'contractAddress'> {
|
|
@@ -1396,10 +1411,7 @@ export function decodeContractCreatedEvent(event: node.ContractEvent): Omit<Cont
|
|
|
1396
1411
|
txId: event.txId,
|
|
1397
1412
|
eventIndex: event.eventIndex,
|
|
1398
1413
|
name: Contract.ContractCreatedEvent.name,
|
|
1399
|
-
fields:
|
|
1400
|
-
address: fields['address'] as Address,
|
|
1401
|
-
parentAddress: fields['parentAddress'] === undefined ? undefined : (fields['parentAddress'] as Address)
|
|
1402
|
-
}
|
|
1414
|
+
fields: toContractCreatedEventFields(fields)
|
|
1403
1415
|
}
|
|
1404
1416
|
}
|
|
1405
1417
|
|
|
@@ -1441,16 +1453,27 @@ export function subscribeEventsFromContract<T extends Fields, M extends Contract
|
|
|
1441
1453
|
return subscribeToEvents(opt, address, fromCount)
|
|
1442
1454
|
}
|
|
1443
1455
|
|
|
1456
|
+
export function addStdIdToFields<F extends Fields>(
|
|
1457
|
+
contract: Contract,
|
|
1458
|
+
fields: F
|
|
1459
|
+
): F | (F & { __stdInterfaceId: HexString }) {
|
|
1460
|
+
const stdInterfaceIdPrefix = '414c5048' // the hex of 'ALPH'
|
|
1461
|
+
return contract.stdInterfaceId === undefined
|
|
1462
|
+
? fields
|
|
1463
|
+
: { ...fields, __stdInterfaceId: stdInterfaceIdPrefix + contract.stdInterfaceId }
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1444
1466
|
export async function testMethod<I, F extends Fields, A extends Arguments, R>(
|
|
1445
1467
|
contract: ContractFactory<I, F>,
|
|
1446
1468
|
methodName: string,
|
|
1447
1469
|
params: Optional<TestContractParams<F, A>, 'testArgs' | 'initialFields'>
|
|
1448
1470
|
): Promise<TestContractResult<R>> {
|
|
1449
1471
|
const txId = params?.txId ?? randomTxId()
|
|
1472
|
+
const initialFields = params.initialFields === undefined ? {} : params.initialFields
|
|
1450
1473
|
const apiParams = contract.contract.toApiTestContractParams(methodName, {
|
|
1451
1474
|
...params,
|
|
1452
1475
|
txId: txId,
|
|
1453
|
-
initialFields:
|
|
1476
|
+
initialFields: addStdIdToFields(contract.contract, initialFields),
|
|
1454
1477
|
testArgs: params.testArgs === undefined ? {} : params.testArgs
|
|
1455
1478
|
})
|
|
1456
1479
|
const apiResult = await getCurrentNodeProvider().contracts.postContractsTestContract(apiParams)
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
Copyright 2018 - 2022 The Alephium Authors
|
|
4
3
|
This file is part of the alephium project.
|
|
@@ -16,3 +15,5 @@ GNU Lesser General Public License for more details.
|
|
|
16
15
|
You should have received a copy of the GNU Lesser General Public License
|
|
17
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
17
|
*/
|
|
18
|
+
|
|
19
|
+
export * from './nft'
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
Copyright 2018 - 2022 The Alephium Authors
|
|
4
3
|
This file is part of the alephium project.
|
|
@@ -16,12 +15,20 @@ GNU Lesser General Public License for more details.
|
|
|
16
15
|
You should have received a copy of the GNU Lesser General Public License
|
|
17
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
|
|
19
|
+
// JSON Schema for the NFT metadata, which is pointed to by the value
|
|
20
|
+
// returned from the `getTokenUri` method of the NFT contract
|
|
21
|
+
export interface NFTMetadata {
|
|
22
|
+
name: string
|
|
23
|
+
description: string
|
|
24
|
+
image: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// JSON Schema for the NFT Collection metadata, which is pointed to by
|
|
28
|
+
// the value returned from the `getCollectionUri` method of the NFT Collection
|
|
29
|
+
// Contract
|
|
30
|
+
export interface NFTCollectionMetadata {
|
|
31
|
+
name: string
|
|
32
|
+
description: string
|
|
33
|
+
image: string
|
|
26
34
|
}
|
|
27
|
-
exports.default = djb2;
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
+
@std(id = #0002)
|
|
1
2
|
Interface INFTCollection {
|
|
2
|
-
|
|
3
|
+
// Collection Uri points to a json file containing metadata for the NFT collection.
|
|
4
|
+
//
|
|
5
|
+
// The schema of the json file is:
|
|
6
|
+
// {
|
|
7
|
+
// "title": "NFT Collection Metadata",
|
|
8
|
+
// "type": "object",
|
|
9
|
+
// "properties": {
|
|
10
|
+
// "name": {
|
|
11
|
+
// "type": "string",
|
|
12
|
+
// "description": "Name of the NFT collection"
|
|
13
|
+
// },
|
|
14
|
+
// "description": {
|
|
15
|
+
// "type": "string",
|
|
16
|
+
// "description": "General description of the NFT collection"
|
|
17
|
+
// },
|
|
18
|
+
// "image": {
|
|
19
|
+
// "type": "string",
|
|
20
|
+
// "description": "A URI to the image that represents the NFT collection"
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
// }
|
|
24
|
+
pub fn getCollectionUri() -> ByteVec
|
|
3
25
|
|
|
4
|
-
pub fn getName() -> ByteVec
|
|
5
|
-
pub fn getSymbol() -> ByteVec
|
|
6
26
|
pub fn totalSupply() -> U256
|
|
27
|
+
|
|
7
28
|
pub fn nftByIndex(index: U256) -> INFT
|
|
8
29
|
}
|
package/std/nft_interface.ral
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
@std(id = #0003)
|
|
1
2
|
Interface INFT {
|
|
3
|
+
// Token Uri points to a json file containing metadata for the NFT.
|
|
4
|
+
//
|
|
5
|
+
// The schema of the json file is:
|
|
6
|
+
// {
|
|
7
|
+
// "title": "NFT Metadata",
|
|
8
|
+
// "type": "object",
|
|
9
|
+
// "properties": {
|
|
10
|
+
// "name": {
|
|
11
|
+
// "type": "string",
|
|
12
|
+
// "description": "Name of the NFT"
|
|
13
|
+
// },
|
|
14
|
+
// "description": {
|
|
15
|
+
// "type": "string",
|
|
16
|
+
// "description": "General description of the NFT"
|
|
17
|
+
// },
|
|
18
|
+
// "image": {
|
|
19
|
+
// "type": "string",
|
|
20
|
+
// "description": "A URI to the image that represents the NFT"
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
// }
|
|
2
24
|
pub fn getTokenUri() -> ByteVec
|
|
3
25
|
}
|