@taquito/tzip12 24.2.0 → 24.3.0-beta.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/lib/errors.js +3 -3
- package/dist/lib/tzip12-contract-abstraction.js +72 -98
- package/dist/lib/version.js +2 -2
- package/dist/taquito-tzip12.es6.js +78 -127
- package/dist/taquito-tzip12.es6.js.map +1 -1
- package/dist/taquito-tzip12.umd.js +230 -279
- package/dist/taquito-tzip12.umd.js.map +1 -1
- package/dist/types/errors.d.ts +3 -3
- package/dist/types/tzip12-contract-abstraction.d.ts +3 -3
- package/package.json +22 -12
- package/LICENSE +0 -202
package/dist/lib/errors.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.InvalidTokenMetadata = exports.TokenIdNotFound = exports.TokenMetadataNo
|
|
|
4
4
|
const core_1 = require("@taquito/core");
|
|
5
5
|
/**
|
|
6
6
|
* @category Error
|
|
7
|
-
*
|
|
7
|
+
* Error that indicates the metadata not being found on the contract
|
|
8
8
|
*/
|
|
9
9
|
class TokenMetadataNotFound extends core_1.TaquitoError {
|
|
10
10
|
constructor(address) {
|
|
@@ -17,7 +17,7 @@ class TokenMetadataNotFound extends core_1.TaquitoError {
|
|
|
17
17
|
exports.TokenMetadataNotFound = TokenMetadataNotFound;
|
|
18
18
|
/**
|
|
19
19
|
* @category Error
|
|
20
|
-
*
|
|
20
|
+
* Error that indicates the token ID not being found
|
|
21
21
|
*/
|
|
22
22
|
class TokenIdNotFound extends core_1.TaquitoError {
|
|
23
23
|
constructor(tokenId) {
|
|
@@ -29,7 +29,7 @@ class TokenIdNotFound extends core_1.TaquitoError {
|
|
|
29
29
|
exports.TokenIdNotFound = TokenIdNotFound;
|
|
30
30
|
/**
|
|
31
31
|
* @category Error
|
|
32
|
-
*
|
|
32
|
+
* Error that indicates that the token metadata is invalid (not compliant with the TZIP-12 standard)
|
|
33
33
|
*/
|
|
34
34
|
class InvalidTokenMetadata extends core_1.TaquitoError {
|
|
35
35
|
constructor(invalidMetadata) {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.Tzip12ContractAbstraction = void 0;
|
|
13
4
|
const michelson_encoder_1 = require("@taquito/michelson-encoder");
|
|
@@ -35,62 +26,53 @@ class Tzip12ContractAbstraction {
|
|
|
35
26
|
this._tzip16ContractAbstraction = new tzip16_1.Tzip16ContractAbstraction(this.contractAbstraction, this.context);
|
|
36
27
|
}
|
|
37
28
|
/**
|
|
38
|
-
*
|
|
29
|
+
* Fetches the contract metadata (according to the Tzip-016 standard)
|
|
39
30
|
* @returns An object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
|
|
40
31
|
* or `Undefined` if the contract has no metadata (non-compliant with Tzip-016)
|
|
41
32
|
*/
|
|
42
|
-
getContractMetadata() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
});
|
|
33
|
+
async getContractMetadata() {
|
|
34
|
+
try {
|
|
35
|
+
const contractMetadata = await this._tzip16ContractAbstraction.getMetadata();
|
|
36
|
+
return contractMetadata.metadata;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
// The contract is not compliant with Tzip-016. There is no contract metadata.
|
|
40
|
+
}
|
|
52
41
|
}
|
|
53
42
|
/**
|
|
54
|
-
*
|
|
43
|
+
* The Tzip-016 "interfaces" field MUST be present in the contract metadata. It should contain "TZIP-012[version-info]"
|
|
55
44
|
* @returns True if "interfaces" field is present and contains "TZIP-012", false otherwise
|
|
56
45
|
*/
|
|
57
|
-
isTzip12Compliant() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return isCompliant;
|
|
69
|
-
});
|
|
46
|
+
async isTzip12Compliant() {
|
|
47
|
+
let isCompliant = false;
|
|
48
|
+
const metadata = await this.getContractMetadata();
|
|
49
|
+
if (metadata) {
|
|
50
|
+
const tzip12Interface = metadata.interfaces?.filter((x) => {
|
|
51
|
+
return x.substring(0, 8) === 'TZIP-012';
|
|
52
|
+
});
|
|
53
|
+
isCompliant = tzip12Interface && tzip12Interface.length !== 0 ? true : false;
|
|
54
|
+
}
|
|
55
|
+
return isCompliant;
|
|
70
56
|
}
|
|
71
57
|
/**
|
|
72
|
-
*
|
|
58
|
+
* Fetches the token metadata for a specified token ID.
|
|
73
59
|
* The function first tries to find a `token_metadata` view in the contract metadata and to execute it with the token ID.
|
|
74
60
|
* If there is no view, the function tries to find a `token_metadata` bigmap in the top-level pairs of the storage.
|
|
75
61
|
* @param tokenId The ID of the token for which we want to retrieve token metadata
|
|
76
62
|
* @returns An object of type `TokenMetadata`
|
|
77
63
|
* @throws {@link TokenIdNotFound, TokenMetadataNotFound, InvalidTokenMetadata}
|
|
78
64
|
*/
|
|
79
|
-
getTokenMetadata(tokenId) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return !tokenMetadata ? this.retrieveTokenMetadataFromBigMap(tokenId) : tokenMetadata;
|
|
83
|
-
});
|
|
65
|
+
async getTokenMetadata(tokenId) {
|
|
66
|
+
const tokenMetadata = await this.retrieveTokenMetadataFromView(tokenId);
|
|
67
|
+
return !tokenMetadata ? this.retrieveTokenMetadataFromBigMap(tokenId) : tokenMetadata;
|
|
84
68
|
}
|
|
85
|
-
retrieveTokenMetadataFromView(tokenId) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return this.executeTokenMetadataView(views['token_metadata'](), tokenId);
|
|
91
|
-
}
|
|
69
|
+
async retrieveTokenMetadataFromView(tokenId) {
|
|
70
|
+
if (await this.getContractMetadata()) {
|
|
71
|
+
const views = await this._tzip16ContractAbstraction.metadataViews();
|
|
72
|
+
if (views && this.hasTokenMetadataView(views)) {
|
|
73
|
+
return this.executeTokenMetadataView(views['token_metadata'](), tokenId);
|
|
92
74
|
}
|
|
93
|
-
}
|
|
75
|
+
}
|
|
94
76
|
}
|
|
95
77
|
hasTokenMetadataView(views) {
|
|
96
78
|
for (const view of Object.keys(views)) {
|
|
@@ -100,35 +82,31 @@ class Tzip12ContractAbstraction {
|
|
|
100
82
|
}
|
|
101
83
|
return false;
|
|
102
84
|
}
|
|
103
|
-
executeTokenMetadataView(tokenMetadataView, tokenId) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return this.formatMetadataToken(tokenId, tokenMap, metadataFromUri);
|
|
112
|
-
});
|
|
85
|
+
async executeTokenMetadataView(tokenMetadataView, tokenId) {
|
|
86
|
+
const tokenMetadata = await tokenMetadataView.executeView(tokenId);
|
|
87
|
+
const tokenMap = Object.values(tokenMetadata)[1];
|
|
88
|
+
if (!michelson_encoder_1.MichelsonMap.isMichelsonMap(tokenMap)) {
|
|
89
|
+
throw new errors_1.TokenMetadataNotFound(this.contractAbstraction.address);
|
|
90
|
+
}
|
|
91
|
+
const metadataFromUri = await this.fetchTokenMetadataFromUri(tokenMap);
|
|
92
|
+
return this.formatMetadataToken(tokenId, tokenMap, metadataFromUri);
|
|
113
93
|
}
|
|
114
|
-
fetchTokenMetadataFromUri(tokenMetadata) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
94
|
+
async fetchTokenMetadataFromUri(tokenMetadata) {
|
|
95
|
+
const uri = tokenMetadata.get('');
|
|
96
|
+
if (uri) {
|
|
97
|
+
try {
|
|
98
|
+
const metadataFromUri = await this.context.metadataProvider.provideMetadata(this.contractAbstraction, (0, utils_1.bytesToString)(uri), this.context);
|
|
99
|
+
return metadataFromUri.metadata;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
if (e.name === 'InvalidUriError') {
|
|
103
|
+
console.warn(`The URI ${(0, utils_1.bytesToString)(uri)} is present in the token metadata, but is invalid.`);
|
|
121
104
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.warn(`The URI ${(0, utils_1.bytesToString)(uri)} is present in the token metadata, but is invalid.`);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
throw e;
|
|
128
|
-
}
|
|
105
|
+
else {
|
|
106
|
+
throw e;
|
|
129
107
|
}
|
|
130
108
|
}
|
|
131
|
-
}
|
|
109
|
+
}
|
|
132
110
|
}
|
|
133
111
|
formatMetadataToken(tokenId, metadataTokenMap, metadataFromUri) {
|
|
134
112
|
const tokenMetadataDecoded = {
|
|
@@ -160,32 +138,28 @@ class Tzip12ContractAbstraction {
|
|
|
160
138
|
}
|
|
161
139
|
return tokenMetadataDecoded;
|
|
162
140
|
}
|
|
163
|
-
retrieveTokenMetadataFromBigMap(tokenId) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return this.formatMetadataToken(tokenId, michelsonMap, metadataFromUri);
|
|
179
|
-
});
|
|
141
|
+
async retrieveTokenMetadataFromBigMap(tokenId) {
|
|
142
|
+
const bigmapTokenMetadataId = await this.findTokenMetadataBigMap();
|
|
143
|
+
let pairNatMap;
|
|
144
|
+
try {
|
|
145
|
+
pairNatMap = await this.context.contract.getBigMapKeyByID(bigmapTokenMetadataId['int'].toString(), tokenId.toString(), new michelson_encoder_1.Schema(tokenMetadataBigMapType));
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
throw new errors_1.TokenIdNotFound(tokenId);
|
|
149
|
+
}
|
|
150
|
+
const michelsonMap = pairNatMap['token_info'];
|
|
151
|
+
if (!michelson_encoder_1.MichelsonMap.isMichelsonMap(michelsonMap)) {
|
|
152
|
+
throw new errors_1.TokenIdNotFound(tokenId);
|
|
153
|
+
}
|
|
154
|
+
const metadataFromUri = await this.fetchTokenMetadataFromUri(michelsonMap);
|
|
155
|
+
return this.formatMetadataToken(tokenId, michelsonMap, metadataFromUri);
|
|
180
156
|
}
|
|
181
|
-
findTokenMetadataBigMap() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return { int: tokenMetadataBigMapId.int };
|
|
188
|
-
});
|
|
157
|
+
async findTokenMetadataBigMap() {
|
|
158
|
+
const tokenMetadataBigMapId = this.contractAbstraction.schema.FindFirstInTopLevelPair(await this.context.readProvider.getStorage(this.contractAbstraction.address, 'head'), tokenMetadataBigMapType);
|
|
159
|
+
if (!tokenMetadataBigMapId || !tokenMetadataBigMapId.int) {
|
|
160
|
+
throw new errors_1.TokenMetadataNotFound(this.contractAbstraction.address);
|
|
161
|
+
}
|
|
162
|
+
return { int: tokenMetadataBigMapId.int };
|
|
189
163
|
}
|
|
190
164
|
}
|
|
191
165
|
exports.Tzip12ContractAbstraction = Tzip12ContractAbstraction;
|
package/dist/lib/version.js
CHANGED
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "24.
|
|
6
|
+
"commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
|
|
7
|
+
"version": "24.3.0-beta.1"
|
|
8
8
|
};
|
|
@@ -3,41 +3,9 @@ import { Tzip16ContractAbstraction, MetadataProvider, DEFAULT_HANDLERS } from '@
|
|
|
3
3
|
import { bytesToString } from '@taquito/utils';
|
|
4
4
|
import { TaquitoError } from '@taquito/core';
|
|
5
5
|
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
24
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
|
-
var e = new Error(message);
|
|
35
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
6
|
/**
|
|
39
7
|
* @category Error
|
|
40
|
-
*
|
|
8
|
+
* Error that indicates the metadata not being found on the contract
|
|
41
9
|
*/
|
|
42
10
|
class TokenMetadataNotFound extends TaquitoError {
|
|
43
11
|
constructor(address) {
|
|
@@ -49,7 +17,7 @@ class TokenMetadataNotFound extends TaquitoError {
|
|
|
49
17
|
}
|
|
50
18
|
/**
|
|
51
19
|
* @category Error
|
|
52
|
-
*
|
|
20
|
+
* Error that indicates the token ID not being found
|
|
53
21
|
*/
|
|
54
22
|
class TokenIdNotFound extends TaquitoError {
|
|
55
23
|
constructor(tokenId) {
|
|
@@ -60,7 +28,7 @@ class TokenIdNotFound extends TaquitoError {
|
|
|
60
28
|
}
|
|
61
29
|
/**
|
|
62
30
|
* @category Error
|
|
63
|
-
*
|
|
31
|
+
* Error that indicates that the token metadata is invalid (not compliant with the TZIP-12 standard)
|
|
64
32
|
*/
|
|
65
33
|
class InvalidTokenMetadata extends TaquitoError {
|
|
66
34
|
constructor(invalidMetadata) {
|
|
@@ -93,62 +61,53 @@ class Tzip12ContractAbstraction {
|
|
|
93
61
|
this._tzip16ContractAbstraction = new Tzip16ContractAbstraction(this.contractAbstraction, this.context);
|
|
94
62
|
}
|
|
95
63
|
/**
|
|
96
|
-
*
|
|
64
|
+
* Fetches the contract metadata (according to the Tzip-016 standard)
|
|
97
65
|
* @returns An object containing the metadata, the uri, an optional integrity check result and an optional sha256 hash
|
|
98
66
|
* or `Undefined` if the contract has no metadata (non-compliant with Tzip-016)
|
|
99
67
|
*/
|
|
100
|
-
getContractMetadata() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
});
|
|
68
|
+
async getContractMetadata() {
|
|
69
|
+
try {
|
|
70
|
+
const contractMetadata = await this._tzip16ContractAbstraction.getMetadata();
|
|
71
|
+
return contractMetadata.metadata;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
// The contract is not compliant with Tzip-016. There is no contract metadata.
|
|
75
|
+
}
|
|
110
76
|
}
|
|
111
77
|
/**
|
|
112
|
-
*
|
|
78
|
+
* The Tzip-016 "interfaces" field MUST be present in the contract metadata. It should contain "TZIP-012[version-info]"
|
|
113
79
|
* @returns True if "interfaces" field is present and contains "TZIP-012", false otherwise
|
|
114
80
|
*/
|
|
115
|
-
isTzip12Compliant() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return isCompliant;
|
|
127
|
-
});
|
|
81
|
+
async isTzip12Compliant() {
|
|
82
|
+
let isCompliant = false;
|
|
83
|
+
const metadata = await this.getContractMetadata();
|
|
84
|
+
if (metadata) {
|
|
85
|
+
const tzip12Interface = metadata.interfaces?.filter((x) => {
|
|
86
|
+
return x.substring(0, 8) === 'TZIP-012';
|
|
87
|
+
});
|
|
88
|
+
isCompliant = tzip12Interface && tzip12Interface.length !== 0 ? true : false;
|
|
89
|
+
}
|
|
90
|
+
return isCompliant;
|
|
128
91
|
}
|
|
129
92
|
/**
|
|
130
|
-
*
|
|
93
|
+
* Fetches the token metadata for a specified token ID.
|
|
131
94
|
* The function first tries to find a `token_metadata` view in the contract metadata and to execute it with the token ID.
|
|
132
95
|
* If there is no view, the function tries to find a `token_metadata` bigmap in the top-level pairs of the storage.
|
|
133
96
|
* @param tokenId The ID of the token for which we want to retrieve token metadata
|
|
134
97
|
* @returns An object of type `TokenMetadata`
|
|
135
98
|
* @throws {@link TokenIdNotFound, TokenMetadataNotFound, InvalidTokenMetadata}
|
|
136
99
|
*/
|
|
137
|
-
getTokenMetadata(tokenId) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const views = yield this._tzip16ContractAbstraction.metadataViews();
|
|
147
|
-
if (views && this.hasTokenMetadataView(views)) {
|
|
148
|
-
return this.executeTokenMetadataView(views['token_metadata'](), tokenId);
|
|
149
|
-
}
|
|
100
|
+
async getTokenMetadata(tokenId) {
|
|
101
|
+
const tokenMetadata = await this.retrieveTokenMetadataFromView(tokenId);
|
|
102
|
+
return !tokenMetadata ? this.retrieveTokenMetadataFromBigMap(tokenId) : tokenMetadata;
|
|
103
|
+
}
|
|
104
|
+
async retrieveTokenMetadataFromView(tokenId) {
|
|
105
|
+
if (await this.getContractMetadata()) {
|
|
106
|
+
const views = await this._tzip16ContractAbstraction.metadataViews();
|
|
107
|
+
if (views && this.hasTokenMetadataView(views)) {
|
|
108
|
+
return this.executeTokenMetadataView(views['token_metadata'](), tokenId);
|
|
150
109
|
}
|
|
151
|
-
}
|
|
110
|
+
}
|
|
152
111
|
}
|
|
153
112
|
hasTokenMetadataView(views) {
|
|
154
113
|
for (const view of Object.keys(views)) {
|
|
@@ -158,35 +117,31 @@ class Tzip12ContractAbstraction {
|
|
|
158
117
|
}
|
|
159
118
|
return false;
|
|
160
119
|
}
|
|
161
|
-
executeTokenMetadataView(tokenMetadataView, tokenId) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return this.formatMetadataToken(tokenId, tokenMap, metadataFromUri);
|
|
170
|
-
});
|
|
120
|
+
async executeTokenMetadataView(tokenMetadataView, tokenId) {
|
|
121
|
+
const tokenMetadata = await tokenMetadataView.executeView(tokenId);
|
|
122
|
+
const tokenMap = Object.values(tokenMetadata)[1];
|
|
123
|
+
if (!MichelsonMap.isMichelsonMap(tokenMap)) {
|
|
124
|
+
throw new TokenMetadataNotFound(this.contractAbstraction.address);
|
|
125
|
+
}
|
|
126
|
+
const metadataFromUri = await this.fetchTokenMetadataFromUri(tokenMap);
|
|
127
|
+
return this.formatMetadataToken(tokenId, tokenMap, metadataFromUri);
|
|
171
128
|
}
|
|
172
|
-
fetchTokenMetadataFromUri(tokenMetadata) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
129
|
+
async fetchTokenMetadataFromUri(tokenMetadata) {
|
|
130
|
+
const uri = tokenMetadata.get('');
|
|
131
|
+
if (uri) {
|
|
132
|
+
try {
|
|
133
|
+
const metadataFromUri = await this.context.metadataProvider.provideMetadata(this.contractAbstraction, bytesToString(uri), this.context);
|
|
134
|
+
return metadataFromUri.metadata;
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
if (e.name === 'InvalidUriError') {
|
|
138
|
+
console.warn(`The URI ${bytesToString(uri)} is present in the token metadata, but is invalid.`);
|
|
179
139
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
console.warn(`The URI ${bytesToString(uri)} is present in the token metadata, but is invalid.`);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw e;
|
|
186
|
-
}
|
|
140
|
+
else {
|
|
141
|
+
throw e;
|
|
187
142
|
}
|
|
188
143
|
}
|
|
189
|
-
}
|
|
144
|
+
}
|
|
190
145
|
}
|
|
191
146
|
formatMetadataToken(tokenId, metadataTokenMap, metadataFromUri) {
|
|
192
147
|
const tokenMetadataDecoded = {
|
|
@@ -218,32 +173,28 @@ class Tzip12ContractAbstraction {
|
|
|
218
173
|
}
|
|
219
174
|
return tokenMetadataDecoded;
|
|
220
175
|
}
|
|
221
|
-
retrieveTokenMetadataFromBigMap(tokenId) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return this.formatMetadataToken(tokenId, michelsonMap, metadataFromUri);
|
|
237
|
-
});
|
|
176
|
+
async retrieveTokenMetadataFromBigMap(tokenId) {
|
|
177
|
+
const bigmapTokenMetadataId = await this.findTokenMetadataBigMap();
|
|
178
|
+
let pairNatMap;
|
|
179
|
+
try {
|
|
180
|
+
pairNatMap = await this.context.contract.getBigMapKeyByID(bigmapTokenMetadataId['int'].toString(), tokenId.toString(), new Schema(tokenMetadataBigMapType));
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
throw new TokenIdNotFound(tokenId);
|
|
184
|
+
}
|
|
185
|
+
const michelsonMap = pairNatMap['token_info'];
|
|
186
|
+
if (!MichelsonMap.isMichelsonMap(michelsonMap)) {
|
|
187
|
+
throw new TokenIdNotFound(tokenId);
|
|
188
|
+
}
|
|
189
|
+
const metadataFromUri = await this.fetchTokenMetadataFromUri(michelsonMap);
|
|
190
|
+
return this.formatMetadataToken(tokenId, michelsonMap, metadataFromUri);
|
|
238
191
|
}
|
|
239
|
-
findTokenMetadataBigMap() {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return { int: tokenMetadataBigMapId.int };
|
|
246
|
-
});
|
|
192
|
+
async findTokenMetadataBigMap() {
|
|
193
|
+
const tokenMetadataBigMapId = this.contractAbstraction.schema.FindFirstInTopLevelPair(await this.context.readProvider.getStorage(this.contractAbstraction.address, 'head'), tokenMetadataBigMapType);
|
|
194
|
+
if (!tokenMetadataBigMapId || !tokenMetadataBigMapId.int) {
|
|
195
|
+
throw new TokenMetadataNotFound(this.contractAbstraction.address);
|
|
196
|
+
}
|
|
197
|
+
return { int: tokenMetadataBigMapId.int };
|
|
247
198
|
}
|
|
248
199
|
}
|
|
249
200
|
|
|
@@ -273,8 +224,8 @@ class Tzip12Module {
|
|
|
273
224
|
|
|
274
225
|
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
|
|
275
226
|
const VERSION = {
|
|
276
|
-
"commitHash": "
|
|
277
|
-
"version": "24.
|
|
227
|
+
"commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
|
|
228
|
+
"version": "24.3.0-beta.1"
|
|
278
229
|
};
|
|
279
230
|
|
|
280
231
|
export { InvalidTokenMetadata, TokenIdNotFound, TokenMetadataNotFound, Tzip12ContractAbstraction, Tzip12Module, VERSION, tzip12 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taquito-tzip12.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"taquito-tzip12.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|