Skip to content

Commit

Permalink
Implement multiple return type for ConditionalStarRelease eth_call
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Apr 21, 2023
1 parent 1865c64 commit 059243b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/conditional-star-release-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,30 @@ export class Indexer implements IndexerInterface {
return result;
}

async getConditionsState (blockHash: string, contractAddress: string): Promise<ValueResult> {
log('getConditionsState: db miss, fetching from upstream server');

const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
const blockNumber = ethers.BigNumber.from(number).toNumber();

const abi = this._abiMap.get(KIND_CONDITIONALSTARRELEASE);
assert(abi);

const contract = new ethers.Contract(contractAddress, abi, this._ethProvider);
const value = await contract.getConditionsState({ blockTag: blockHash });

const result: ValueResult = {
value: {
value0: value[0],
value1: value[1],
value2: value[2],
value3: value[3],
}
};

return result;
}

async getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise<ValueResult> {
return this._baseIndexer.getStorageValue(
storageLayout,
Expand Down
16 changes: 16 additions & 0 deletions packages/conditional-star-release-watcher/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,22 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
return indexer.getRemainingStars(blockHash, contractAddress, _participant);
},

getConditionsState: (
_: any,
{ blockHash, contractAddress }: { blockHash: string, contractAddress: string },
__: any,
info: GraphQLResolveInfo
): Promise<ValueResult> => {
log('getConditionsState', blockHash, contractAddress);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getConditionsState').inc(1);

// Set cache-control hints
// setGQLCacheHints(info, {}, gqlCacheConfig);

return indexer.getConditionsState(blockHash, contractAddress);
},

events: async (_: any, { blockHash, contractAddress, name }: { blockHash: string, contractAddress: string, name?: string }) => {
log('events', blockHash, contractAddress, name);
gqlTotalQueryCount.inc(1);
Expand Down
13 changes: 13 additions & 0 deletions packages/conditional-star-release-watcher/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,24 @@ type Query {
getForfeited(blockHash: String!, contractAddress: String!, _participant: String!): ResultBooleanArray!
hasForfeitedBatch(blockHash: String!, contractAddress: String!, _participant: String!, _batch: Int!): ResultBoolean!
getRemainingStars(blockHash: String!, contractAddress: String!, _participant: String!): ResultIntArray!
getConditionsState(blockHash: String!, contractAddress: String!): ResultConditionStateType!
getSyncStatus: SyncStatus
getStateByCID(cid: String!): ResultState
getState(blockHash: String!, contractAddress: String!, kind: String): ResultState
}

type ConditionStateType {
value0: [String!]!
value1: [BigInt!]!
value2: [BigInt!]!
value3: [BigInt!]!
}

type ResultConditionStateType {
value: ConditionStateType!
proof: Proof
}

type ResultBoolean {
value: Boolean!
proof: Proof
Expand Down

0 comments on commit 059243b

Please sign in to comment.