Skip to content

Commit

Permalink
Merge pull request #52 from near/lookup-set
Browse files Browse the repository at this point in the history
add lookup set
  • Loading branch information
volovyks authored May 20, 2022
2 parents bbfd0d4 + f36a4a2 commit b43fa07
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/collections/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { LookupMap } from "./lookup-map";
import { Vector } from "./vector";
import { LookupSet } from "./lookup-set";

export {
LookupMap,
Vector
Vector,
LookupSet
}
34 changes: 34 additions & 0 deletions src/collections/lookup-set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as near from '../api'

export class LookupSet {
constructor(keyPrefix) {
this.keyPrefix = keyPrefix
}

contains(key) {
let storageKey = this.keyPrefix + key
return near.jsvmStorageHasKey(storageKey)
}

remove(key) {
let storageKey = this.keyPrefix + key
if (near.jsvmStorageRemove(storageKey)) {
return near.storageGetEvicted()
}
return null
}

set(key) {
let storageKey = this.keyPrefix + key
if (near.jsvmStorageWrite(storageKey, '')) {
return near.storageGetEvicted()
}
return null
}

extend(kvs) {
for(let kv of kvs) {
this.set(kv[0])
}
}
}
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import {
} from './near-contract'

import * as near from './api'
import { LookupMap } from './collections/lookup-map'
import {
LookupMap,
Vector,
LookupSet
} from './collections'

export {
call,
view,
NearBindgen,
NearContract,
near,
LookupMap
LookupMap,
Vector,
LookupSet
}

0 comments on commit b43fa07

Please sign in to comment.