@alephium/web3 0.8.2-test.3 → 0.9.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 +12 -11
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/api-explorer.d.ts +7 -7
- package/dist/src/api/node-provider.d.ts +16 -1
- package/dist/src/api/node-provider.js +26 -20
- package/dist/src/api/types.d.ts +5 -5
- package/dist/src/api/types.js +5 -9
- package/dist/src/contract/contract.d.ts +25 -21
- package/dist/src/contract/contract.js +70 -52
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/signer/types.d.ts +5 -5
- package/dist/src/token/index.d.ts +1 -0
- package/dist/src/token/index.js +34 -0
- package/dist/src/token/nft.d.ts +10 -0
- package/dist/src/token/nft.js +19 -0
- package/dist/src/transaction/status.d.ts +1 -1
- package/dist/src/utils/subscription.d.ts +2 -2
- package/dist/src/utils/utils.d.ts +3 -3
- 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/src/token/index.ts +19 -0
- package/src/token/nft.ts +34 -0
- package/std/fungible_token_interface.ral +1 -0
- package/std/nft_collection_interface.ral +24 -3
- package/std/nft_interface.ral +22 -0
- package/jest-config.json +0 -11
package/src/api/node-provider.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { ApiRequestArguments, ApiRequestHandler, forwardRequests, request, Token
|
|
|
20
20
|
import { Api as NodeApi } from './api-alephium'
|
|
21
21
|
import { DEFAULT_THROTTLE_FETCH } from './utils'
|
|
22
22
|
import { HexString } from '../contract'
|
|
23
|
-
import { addressFromTokenId } from '../utils'
|
|
23
|
+
import { addressFromTokenId, groupOfAddress } from '../utils'
|
|
24
24
|
|
|
25
25
|
function initializeNodeApi(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): NodeApi<string> {
|
|
26
26
|
const nodeApi = new NodeApi<string>({
|
|
@@ -33,7 +33,21 @@ function initializeNodeApi(baseUrl: string, apiKey?: string, customFetch?: typeo
|
|
|
33
33
|
return nodeApi
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
interface NodeProviderApis {
|
|
37
|
+
wallets: NodeApi<string>['wallets']
|
|
38
|
+
infos: NodeApi<string>['infos']
|
|
39
|
+
blockflow: NodeApi<string>['blockflow']
|
|
40
|
+
addresses: NodeApi<string>['addresses']
|
|
41
|
+
transactions: NodeApi<string>['transactions']
|
|
42
|
+
mempool: NodeApi<string>['mempool']
|
|
43
|
+
contracts: NodeApi<string>['contracts']
|
|
44
|
+
multisig: NodeApi<string>['multisig']
|
|
45
|
+
utils: NodeApi<string>['utils']
|
|
46
|
+
miners: NodeApi<string>['miners']
|
|
47
|
+
events: NodeApi<string>['events']
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class NodeProvider implements NodeProviderApis {
|
|
37
51
|
readonly wallets: NodeApi<string>['wallets']
|
|
38
52
|
readonly infos: NodeApi<string>['infos']
|
|
39
53
|
readonly blockflow: NodeApi<string>['blockflow']
|
|
@@ -50,13 +64,9 @@ export class NodeProvider {
|
|
|
50
64
|
constructor(provider: NodeProvider)
|
|
51
65
|
constructor(handler: ApiRequestHandler)
|
|
52
66
|
constructor(param0: string | NodeProvider | ApiRequestHandler, apiKey?: string, customFetch?: typeof fetch) {
|
|
53
|
-
let nodeApi:
|
|
67
|
+
let nodeApi: NodeProviderApis
|
|
54
68
|
if (typeof param0 === 'string') {
|
|
55
|
-
|
|
56
|
-
nodeApi = {
|
|
57
|
-
...api,
|
|
58
|
-
fetchStdTokenMetaData: async (tokenId: string) => fetchStdTokenMetaData(api.contracts, tokenId)
|
|
59
|
-
}
|
|
69
|
+
nodeApi = initializeNodeApi(param0, apiKey, customFetch)
|
|
60
70
|
} else if (typeof param0 === 'function') {
|
|
61
71
|
nodeApi = new NodeProvider('https://1.2.3.4:0')
|
|
62
72
|
forwardRequests(nodeApi, param0 as ApiRequestHandler)
|
|
@@ -92,24 +102,30 @@ export class NodeProvider {
|
|
|
92
102
|
|
|
93
103
|
// Only use this when the token is following the standard token interface
|
|
94
104
|
fetchStdTokenMetaData = async (tokenId: HexString): Promise<TokenMetaData> => {
|
|
95
|
-
|
|
105
|
+
const group = 0
|
|
106
|
+
const address = addressFromTokenId(tokenId)
|
|
107
|
+
const calls = Array.from([0, 1, 2, 3], (index) => ({ methodIndex: index, group: group, address: address }))
|
|
108
|
+
const result = await this.contracts.postContractsMulticallContract({
|
|
109
|
+
calls: calls
|
|
110
|
+
})
|
|
111
|
+
return {
|
|
112
|
+
symbol: result.results[0].returns[0].value as any as string,
|
|
113
|
+
name: result.results[1].returns[0].value as any as string,
|
|
114
|
+
decimals: Number(result.results[2].returns[0].value as any as string),
|
|
115
|
+
totalSupply: BigInt(result.results[3].returns[0].value as any as string)
|
|
116
|
+
}
|
|
96
117
|
}
|
|
97
|
-
}
|
|
98
118
|
|
|
99
|
-
async
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
symbol: result.results[0].returns[0].value as any as string,
|
|
111
|
-
name: result.results[1].returns[0].value as any as string,
|
|
112
|
-
decimals: Number(result.results[2].returns[0].value as any as string),
|
|
113
|
-
totalSupply: BigInt(result.results[3].returns[0].value as any as string)
|
|
119
|
+
guessStdInterfaceId = async (tokenId: HexString): Promise<HexString | undefined> => {
|
|
120
|
+
const address = addressFromTokenId(tokenId)
|
|
121
|
+
const group = groupOfAddress(address)
|
|
122
|
+
const rawState = await this.contracts.getContractsAddressState(addressFromTokenId(tokenId), { group })
|
|
123
|
+
const lastImmField = rawState.immFields.slice(-1).pop()?.value
|
|
124
|
+
const interfaceIdPrefix = '414c5048' // the hex of 'ALPH'
|
|
125
|
+
if (typeof lastImmField === 'string' && lastImmField.startsWith(interfaceIdPrefix)) {
|
|
126
|
+
return lastImmField.slice(8)
|
|
127
|
+
} else {
|
|
128
|
+
return undefined
|
|
129
|
+
}
|
|
114
130
|
}
|
|
115
131
|
}
|
package/src/api/types.ts
CHANGED
|
@@ -136,7 +136,12 @@ export function toApiVal(v: Val, tpe: string): node.Val {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function _fromApiVal(
|
|
139
|
+
function _fromApiVal(
|
|
140
|
+
vals: node.Val[],
|
|
141
|
+
valIndex: number,
|
|
142
|
+
tpe: string,
|
|
143
|
+
systemEvent = false
|
|
144
|
+
): [result: Val, nextIndex: number] {
|
|
140
145
|
if (vals.length === 0) {
|
|
141
146
|
throw new Error('Not enough Vals')
|
|
142
147
|
}
|
|
@@ -146,7 +151,7 @@ function _fromApiVal(vals: node.Val[], valIndex: number, tpe: string): [result:
|
|
|
146
151
|
return [firstVal.value as boolean, valIndex + 1]
|
|
147
152
|
} else if ((tpe === 'U256' || tpe === 'I256') && firstVal.type === tpe) {
|
|
148
153
|
return [fromApiNumber256(firstVal.value as string), valIndex + 1]
|
|
149
|
-
} else if ((tpe === 'ByteVec' || tpe === 'Address') && firstVal.type === tpe) {
|
|
154
|
+
} else if ((tpe === 'ByteVec' || tpe === 'Address') && (firstVal.type === tpe || systemEvent)) {
|
|
150
155
|
return [firstVal.value as string, valIndex + 1]
|
|
151
156
|
} else {
|
|
152
157
|
const [baseType, dims] = decodeArrayType(tpe)
|
|
@@ -162,26 +167,16 @@ function _fromApiVal(vals: node.Val[], valIndex: number, tpe: string): [result:
|
|
|
162
167
|
}
|
|
163
168
|
}
|
|
164
169
|
|
|
165
|
-
export function fromApiVals(
|
|
166
|
-
vals: node.Val[],
|
|
167
|
-
names: string[],
|
|
168
|
-
types: string[],
|
|
169
|
-
optionalNames: string[] = [],
|
|
170
|
-
optionalTypes: string[] = []
|
|
171
|
-
): NamedVals {
|
|
170
|
+
export function fromApiVals(vals: node.Val[], names: string[], types: string[], systemEvent = false): NamedVals {
|
|
172
171
|
let valIndex = 0
|
|
173
172
|
const result: NamedVals = {}
|
|
174
173
|
types.forEach((currentType, index) => {
|
|
175
174
|
const currentName = names[`${index}`]
|
|
176
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType)
|
|
175
|
+
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType, systemEvent)
|
|
177
176
|
valIndex = nextIndex
|
|
178
177
|
result[`${currentName}`] = val
|
|
179
178
|
})
|
|
180
|
-
|
|
181
|
-
return result
|
|
182
|
-
}
|
|
183
|
-
const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes)
|
|
184
|
-
return { ...result, ...optionalFields }
|
|
179
|
+
return result
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
export function fromApiArray(vals: node.Val[], types: string[]): Val[] {
|
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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export * from './nft'
|
package/src/token/nft.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
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
|
|
34
|
+
}
|
|
@@ -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
|
}
|
package/jest-config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testPathIgnorePatterns": [".*/node_modules/"],
|
|
3
|
-
"transform": {
|
|
4
|
-
"^.+\\.(t|j)sx?$": "ts-jest"
|
|
5
|
-
},
|
|
6
|
-
"testMatch": ["**/*.test.ts"],
|
|
7
|
-
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
8
|
-
"collectCoverage": true,
|
|
9
|
-
"coverageDirectory": "./coverage/",
|
|
10
|
-
"collectCoverageFrom": ["src/**/*.ts"]
|
|
11
|
-
}
|