@alephium/web3 0.14.5 → 0.15.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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/explorer-provider.js +1 -1
- package/dist/src/api/node-provider.js +1 -1
- package/dist/src/api/types.d.ts +16 -0
- package/dist/src/contract/contract.d.ts +12 -9
- package/dist/src/contract/contract.js +33 -3
- package/dist/src/contract/events.d.ts +6 -2
- package/dist/src/contract/events.js +4 -0
- package/dist/src/token/nft.d.ts +8 -23
- package/dist/src/token/nft.js +20 -20
- package/dist/src/transaction/status.d.ts +3 -2
- package/dist/src/transaction/status.js +7 -3
- package/dist/src/utils/subscription.d.ts +1 -0
- package/dist/src/utils/subscription.js +3 -0
- package/package.json +1 -1
- package/src/api/explorer-provider.ts +1 -1
- package/src/api/node-provider.ts +1 -1
- package/src/api/types.ts +18 -0
- package/src/contract/contract.ts +48 -13
- package/src/contract/events.ts +13 -2
- package/src/token/nft.ts +21 -39
- package/src/transaction/status.ts +15 -3
- package/src/utils/subscription.ts +4 -0
package/src/token/nft.ts
CHANGED
|
@@ -20,52 +20,32 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20
20
|
// returned from the `getTokenUri` method of the NFT contract
|
|
21
21
|
|
|
22
22
|
import 'cross-fetch/polyfill'
|
|
23
|
+
import { NFTCollectionUriMetaData, NFTTokenUriMetaData } from '../api'
|
|
23
24
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
attributes?: [
|
|
29
|
-
{
|
|
30
|
-
trait_type: string
|
|
31
|
-
value: string | number | boolean
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// JSON Schema for the NFT Collection metadata, which is pointed to by
|
|
37
|
-
// the value returned from the `getCollectionUri` method of the NFT Collection
|
|
38
|
-
// Contract
|
|
39
|
-
export interface NFTCollectionMetadata {
|
|
40
|
-
name: string
|
|
41
|
-
description: string
|
|
42
|
-
image: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const validNFTMetadataFields = ['name', 'description', 'image', 'attributes']
|
|
46
|
-
export const validNFTMetadataAttributesFields = ['trait_type', 'value']
|
|
47
|
-
export const validNFTMetadataAttributeTypes = ['string', 'number', 'boolean']
|
|
48
|
-
export const validNFTCollectionMetadataFields = ['name', 'description', 'image']
|
|
25
|
+
export const validNFTTokenUriMetaDataFields = ['name', 'description', 'image', 'attributes']
|
|
26
|
+
export const validNFTTokenUriMetaDataAttributesFields = ['trait_type', 'value']
|
|
27
|
+
export const validNFTUriMetaDataAttributeTypes = ['string', 'number', 'boolean']
|
|
28
|
+
export const validNFTCollectionUriMetaDataFields = ['name', 'description', 'image']
|
|
49
29
|
|
|
50
|
-
export function
|
|
30
|
+
export function validateNFTTokenUriMetaData(metadata: any): NFTTokenUriMetaData {
|
|
51
31
|
Object.keys(metadata).forEach((key) => {
|
|
52
|
-
if (!
|
|
53
|
-
throw new Error(`Invalid field ${key}, only ${
|
|
32
|
+
if (!validNFTTokenUriMetaDataFields.includes(key)) {
|
|
33
|
+
throw new Error(`Invalid field ${key}, only ${validNFTTokenUriMetaDataFields} are allowed`)
|
|
54
34
|
}
|
|
55
35
|
})
|
|
56
36
|
|
|
57
37
|
const name = validateNonEmptyString(metadata, 'name')
|
|
58
38
|
const description = validateNonEmptyStringIfExists(metadata, 'description')
|
|
59
39
|
const image = validateNonEmptyString(metadata, 'image')
|
|
60
|
-
const attributes =
|
|
40
|
+
const attributes = validateNFTTokenUriMetaDataAttributes(metadata['attributes'])
|
|
61
41
|
|
|
62
42
|
return { name, description, image, attributes }
|
|
63
43
|
}
|
|
64
44
|
|
|
65
|
-
export function
|
|
45
|
+
export function validateNFTCollectionUriMetaData(metadata: any): NFTCollectionUriMetaData {
|
|
66
46
|
Object.keys(metadata).forEach((key) => {
|
|
67
|
-
if (!
|
|
68
|
-
throw new Error(`Invalid field ${key}, only ${
|
|
47
|
+
if (!validNFTCollectionUriMetaDataFields.includes(key)) {
|
|
48
|
+
throw new Error(`Invalid field ${key}, only ${validNFTCollectionUriMetaDataFields} are allowed`)
|
|
69
49
|
}
|
|
70
50
|
})
|
|
71
51
|
|
|
@@ -76,13 +56,13 @@ export function validateNFTCollectionMetadata(metadata: any): NFTCollectionMetad
|
|
|
76
56
|
return { name, description, image }
|
|
77
57
|
}
|
|
78
58
|
|
|
79
|
-
export async function
|
|
59
|
+
export async function validateNFTBaseUri(nftBaseUri: string, maxSupply: number): Promise<NFTTokenUriMetaData[]> {
|
|
80
60
|
if (isInteger(maxSupply) && maxSupply > 0) {
|
|
81
|
-
const nftMetadataz:
|
|
61
|
+
const nftMetadataz: NFTTokenUriMetaData[] = []
|
|
82
62
|
|
|
83
63
|
for (let i = 0; i < maxSupply; i++) {
|
|
84
64
|
const nftMetadata = await fetchNFTMetadata(nftBaseUri, i)
|
|
85
|
-
const validatedNFTMetadata =
|
|
65
|
+
const validatedNFTMetadata = validateNFTTokenUriMetaData(nftMetadata)
|
|
86
66
|
nftMetadataz.push(validatedNFTMetadata)
|
|
87
67
|
}
|
|
88
68
|
|
|
@@ -92,7 +72,7 @@ export async function validateEnumerableNFTBaseUri(nftBaseUri: string, maxSupply
|
|
|
92
72
|
}
|
|
93
73
|
}
|
|
94
74
|
|
|
95
|
-
function
|
|
75
|
+
function validateNFTTokenUriMetaDataAttributes(attributes: any): NFTTokenUriMetaData['attributes'] {
|
|
96
76
|
if (!!attributes) {
|
|
97
77
|
if (!Array.isArray(attributes)) {
|
|
98
78
|
throw new Error(`Field 'attributes' should be an array`)
|
|
@@ -104,8 +84,10 @@ function validateNFTMetadataAttributes(attributes: any): NFTMetadata['attributes
|
|
|
104
84
|
}
|
|
105
85
|
|
|
106
86
|
Object.keys(item).forEach((key) => {
|
|
107
|
-
if (!
|
|
108
|
-
throw new Error(
|
|
87
|
+
if (!validNFTTokenUriMetaDataAttributesFields.includes(key)) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Invalid field ${key} for attributes, only ${validNFTTokenUriMetaDataAttributesFields} are allowed`
|
|
90
|
+
)
|
|
109
91
|
}
|
|
110
92
|
})
|
|
111
93
|
|
|
@@ -114,7 +96,7 @@ function validateNFTMetadataAttributes(attributes: any): NFTMetadata['attributes
|
|
|
114
96
|
})
|
|
115
97
|
}
|
|
116
98
|
|
|
117
|
-
return attributes as
|
|
99
|
+
return attributes as NFTTokenUriMetaData['attributes']
|
|
118
100
|
}
|
|
119
101
|
|
|
120
102
|
function validateNonEmptyString(obj: object, field: string): string {
|
|
@@ -26,12 +26,20 @@ export class TxStatusSubscription extends Subscription<TxStatus> {
|
|
|
26
26
|
readonly txId: string
|
|
27
27
|
readonly fromGroup?: number
|
|
28
28
|
readonly toGroup?: number
|
|
29
|
+
readonly confirmations: number
|
|
29
30
|
|
|
30
|
-
constructor(
|
|
31
|
+
constructor(
|
|
32
|
+
options: SubscribeOptions<TxStatus>,
|
|
33
|
+
txId: string,
|
|
34
|
+
fromGroup?: number,
|
|
35
|
+
toGroup?: number,
|
|
36
|
+
confirmations?: number
|
|
37
|
+
) {
|
|
31
38
|
super(options)
|
|
32
39
|
this.txId = txId
|
|
33
40
|
this.fromGroup = fromGroup
|
|
34
41
|
this.toGroup = toGroup
|
|
42
|
+
this.confirmations = confirmations ?? 1
|
|
35
43
|
|
|
36
44
|
this.startPolling()
|
|
37
45
|
}
|
|
@@ -45,6 +53,9 @@ export class TxStatusSubscription extends Subscription<TxStatus> {
|
|
|
45
53
|
})
|
|
46
54
|
|
|
47
55
|
await this.messageCallback(txStatus)
|
|
56
|
+
if (txStatus.type === 'Confirmed' && (txStatus as node.Confirmed).chainConfirmations >= this.confirmations) {
|
|
57
|
+
this.unsubscribe()
|
|
58
|
+
}
|
|
48
59
|
} catch (err) {
|
|
49
60
|
await this.errorCallback(err, this)
|
|
50
61
|
}
|
|
@@ -55,7 +66,8 @@ export function subscribeToTxStatus(
|
|
|
55
66
|
options: SubscribeOptions<TxStatus>,
|
|
56
67
|
txId: string,
|
|
57
68
|
fromGroup?: number,
|
|
58
|
-
toGroup?: number
|
|
69
|
+
toGroup?: number,
|
|
70
|
+
confirmations?: number
|
|
59
71
|
): TxStatusSubscription {
|
|
60
|
-
return new TxStatusSubscription(options, txId, fromGroup, toGroup)
|
|
72
|
+
return new TxStatusSubscription(options, txId, fromGroup, toGroup, confirmations)
|
|
61
73
|
}
|