-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConseilJS 5.0.2-beta.3 #303
Changes from all commits
f9df341
db93274
ffa4952
8d4c9cc
a599924
2723af4
f7d2a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,13 +267,13 @@ export namespace TezosConseilClient { | |
/** | ||
* Returns big_map data for a given contract if any is available. | ||
* | ||
* @param serverInfo Conseil server connection definition. | ||
* @param accountID Account hash to query for. | ||
* @param serverInfo Conseil server connection definition. | ||
* @param contract Contract address to query for. | ||
*/ | ||
export async function getBigMapData(serverInfo: ConseilServerInfo, accountID: string): Promise<ContractMapDetails | undefined> { | ||
if (!accountID.startsWith('KT1')) { throw new Error('Invalid address'); } | ||
export async function getBigMapData(serverInfo: ConseilServerInfo, contract: string): Promise<ContractMapDetails | undefined> { | ||
if (!contract.startsWith('KT1')) { throw new Error('Invalid address'); } | ||
|
||
const ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.addFields(ConseilQueryBuilder.addPredicate(ConseilQueryBuilder.blankQuery(), 'account_id', ConseilOperator.EQ, [accountID], false), 'big_map_id'), 100); | ||
const ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.addFields(ConseilQueryBuilder.addPredicate(ConseilQueryBuilder.blankQuery(), 'account_id', ConseilOperator.EQ, [contract], false), 'big_map_id'), 100); | ||
const ownerResult = await getTezosEntityData(serverInfo, serverInfo.network, 'originated_account_maps', ownerQuery); | ||
|
||
if (ownerResult.length < 1) { return undefined; } | ||
|
@@ -296,7 +296,45 @@ export namespace TezosConseilClient { | |
maps.push({definition, content}); | ||
} | ||
|
||
return { contract: accountID, maps }; | ||
return { contract, maps }; | ||
} | ||
|
||
/** | ||
* Returns a value for a given plain-text key. The big map id is either provided as a paramter or the smallest of the possibly multiple big maps associated with the given contract address is used. Note that sometimes key values must be wrapped in quotes for key types that are non-numeric and not byte type. | ||
* | ||
* Under normal circumstances these keys are hashed and TezosNodeReader.getValueForBigMapKey() expects such an encoded key. However, with the Conseil indexer it's possible to query for plain-text keys. | ||
* | ||
* @param serverInfo Conseil server connection definition. | ||
* @param key Key to query for. | ||
* @param contract Optional contract address to be used to identify an associated big map. | ||
* @param mapIndex Optional big map index to query, but one of contract or mapIndex must be provided. | ||
*/ | ||
export async function getBigMapValueForKey(serverInfo: ConseilServerInfo, key: string, contract: string = '', mapIndex: number = -1): Promise<string> { | ||
if (!contract.startsWith('KT1')) { throw new Error('Invalid address'); } | ||
if (key.length < 1) { throw new Error('Invalid key'); } | ||
if (mapIndex < 0 && contract.length === 0) { throw new Error('One of contract or mapIndex must be specified'); } | ||
|
||
if (mapIndex < 0 && contract.length > 0) { | ||
let ownerQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.blankQuery(), 1); | ||
ownerQuery = ConseilQueryBuilder.addFields(ownerQuery, 'big_map_id'); | ||
ownerQuery = ConseilQueryBuilder.addPredicate(ownerQuery, 'account_id', ConseilOperator.EQ, [contract], false); | ||
ownerQuery = ConseilQueryBuilder.addOrdering(ownerQuery, 'big_map_id', ConseilSortDirection.DESC); | ||
|
||
const ownerResult = await getTezosEntityData(serverInfo, serverInfo.network, 'originated_account_maps', ownerQuery); | ||
|
||
if (ownerResult.length < 1) { throw new Error(`Could not find any maps for ${contract}`); } | ||
mapIndex = ownerResult[0]; | ||
} | ||
|
||
let contentQuery = ConseilQueryBuilder.setLimit(ConseilQueryBuilder.blankQuery(), 1); | ||
contentQuery = ConseilQueryBuilder.addFields(contentQuery, 'value'); | ||
contentQuery = ConseilQueryBuilder.addPredicate(contentQuery, 'key', ConseilOperator.EQ, [key], false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it not possible to automatically encode the key? I forget the details. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not at this time, contract parser will need updates. |
||
contentQuery = ConseilQueryBuilder.addPredicate(contentQuery, 'big_map_id', ConseilOperator.EQ, [mapIndex], false); | ||
const contentResult = await getTezosEntityData(serverInfo, serverInfo.network, 'big_map_contents', contentQuery); | ||
|
||
if (contentResult.length < 1) { throw new Error(`Could not a value for key ${key} in map ${mapIndex}`); } | ||
|
||
return contentResult[0]; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should specify whether this is encoded or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs were updated