@@ -2,34 +2,13 @@ import {ITokenScriptEngine, ScriptSourceType} from "../../IEngine";
2
2
import { ScriptInfo , SourceInterface } from "./SourceInterface" ;
3
3
4
4
const REGISTRY_7738 = "0x0077380bCDb2717C9640e892B9d5Ee02Bb5e0682" ;
5
- const HOLESKY_ID = 17000 ; // TODO: Source this from engine
6
- const cacheTimeout = 60 * 1000 ; // 1 minute cache validity
7
-
8
- //cache entries
9
- export interface ScriptEntry {
10
- scriptURIs : string [ ] ;
11
- timeStamp : number ;
12
- }
13
-
14
- export interface RegistryMetaData {
15
- scriptData : ScriptInfo [ ] ;
16
- timeStamp : number ;
17
- }
18
-
19
- const cachedResults = new Map < string , ScriptEntry > ( ) ;
20
- const cachedMetaDataResults = new Map < string , RegistryMetaData > ( ) ;
21
5
22
6
/**
23
7
* The ScriptURI source implement ethereum EIP-5169
24
8
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5169.md
25
9
*/
26
10
export class RegistryScriptURI implements SourceInterface {
27
11
28
- // Development deployment of 7738 on Holesky only
29
- // TODO: Replace with multichain address once available
30
-
31
-
32
-
33
12
constructor ( private context : ITokenScriptEngine ) {
34
13
}
35
14
@@ -51,56 +30,10 @@ export class RegistryScriptURI implements SourceInterface {
51
30
return registryScripts ;
52
31
}
53
32
54
- // This returns all entries but the 7738 calling function currently selects the first entry
55
- // TODO: Create selector that displays icon and name for each entry, in order returned
56
- // TODO: Use global deployed address for 7738
57
- public async get7738Entry ( chain : string , contractAddr : string ) : Promise < string [ ] > {
58
-
59
- // use 1 minute persistence fetch cache
60
- let cachedResult = this . checkCachedResult ( chain , contractAddr ) ;
61
-
62
- if ( cachedResult . length > 0 ) {
63
- return cachedResult ;
64
- }
65
-
66
- const chainId : number = parseInt ( chain ) ;
67
-
68
- const provider = await this . context . getWalletAdapter ( ) ;
69
- let uri : string | string [ ] | null ;
70
-
71
- try {
72
- uri = Array . from ( await provider . call (
73
- chainId , REGISTRY_7738 , "scriptURI" , [
74
- {
75
- internalType : "address" ,
76
- name : "" ,
77
- type : "address" ,
78
- value : contractAddr
79
- } ] , [ "string[]" ]
80
- ) ) as string [ ] ;
81
- } catch ( e ) {
82
- uri = "" ;
83
- }
84
-
85
- if ( uri && Array . isArray ( uri ) && uri . length > 0 ) {
86
- this . storeResult ( chain , contractAddr , uri ) ;
87
- return uri ;
88
- } else {
89
- return [ ] ;
90
- }
91
- }
92
-
93
33
public async get7738Metadata ( chain : string , contractAddr : string ) : Promise < ScriptInfo [ ] > {
94
34
95
35
const chainId : number = parseInt ( chain ) ;
96
36
97
- // use 1 minute persistence fetch cache
98
- let cachedResult = this . checkCachedMetaData ( chain , contractAddr ) ;
99
-
100
- if ( cachedResult . length > 0 ) {
101
- return cachedResult ;
102
- }
103
-
104
37
const provider = await this . context . getWalletAdapter ( ) ;
105
38
let scriptSourceData : any ;
106
39
@@ -176,85 +109,4 @@ export class RegistryScriptURI implements SourceInterface {
176
109
return sourceElements ;
177
110
}
178
111
179
- private storeResult ( chain : string , contractAddr : string , uris : string [ ] ) {
180
- // remove out of date entries
181
- cachedResults . forEach ( ( value , key ) => {
182
- if ( value . timeStamp < ( Date . now ( ) - cacheTimeout ) ) {
183
- cachedResults . delete ( key ) ;
184
- }
185
- } ) ;
186
-
187
- cachedResults . set ( chain + "-" + contractAddr , {
188
- scriptURIs : uris ,
189
- timeStamp : Date . now ( )
190
- } ) ;
191
- }
192
-
193
- private checkCachedResult ( chain : string , contractAddress : string ) : string [ ] {
194
- const key = chain + "-" + contractAddress ;
195
- const mapping = cachedResults . get ( key ) ;
196
- if ( mapping ) {
197
- if ( mapping . timeStamp < ( Date . now ( ) - cacheTimeout ) ) {
198
- //out of date result, remove key
199
- cachedResults . delete ( key ) ;
200
- return [ ]
201
- } else {
202
- //consoleLog("Can use cache");
203
- return mapping . scriptURIs ;
204
- }
205
- } else {
206
- return [ ] ;
207
- }
208
- }
209
-
210
- private checkCachedMetaData ( chain : string , contractAddress : string ) : ScriptInfo [ ] {
211
- const key = chain + "-" + contractAddress ;
212
- this . removeOutOfDateEntries ( ) ;
213
- const mapping = cachedMetaDataResults . get ( key ) ;
214
- if ( mapping ) {
215
- return mapping . scriptData ;
216
- } else {
217
- return [ ] ;
218
- }
219
- }
220
-
221
- //ensure memory usage is kept to a minimum
222
- private removeOutOfDateEntries ( ) {
223
- const currentTime = Date . now ( ) ;
224
- for ( const [ key , value ] of cachedMetaDataResults ) {
225
- if ( currentTime - value . timeStamp > cacheTimeout ) {
226
- cachedMetaDataResults . delete ( key ) ;
227
- }
228
- }
229
- }
230
-
231
- /*public async getAuthenticationStatus(contractAddress: string, order: number) {
232
- const wallet = await this.engine.getWalletAdapter();
233
- const chain = this.context.getCurrentTokenContext()?.chainId ?? await wallet.getChain();
234
-
235
- let isAuthorised: boolean = false;
236
-
237
- try {
238
- isAuthorised = await wallet.call(
239
- chain, HOLESKY_DEV_7738, "isAuthenticated", [
240
- {
241
- internalType: "address",
242
- name: "",
243
- type: "address",
244
- value: contractAddress
245
- },
246
- {
247
- internalType: "uint256",
248
- name: "",
249
- type: "uint256",
250
- value: order
251
- }], ["bool"]
252
- );
253
- } catch (e) {
254
-
255
- }
256
-
257
- return isAuthorised;
258
- }*/
259
-
260
112
}
0 commit comments