Skip to content
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

Feat/engt 1220 #611

Merged
merged 37 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6e05343
added nfts to insight gathering
OzanEm Feb 3, 2023
1bb8766
added basic nft query version
OzanEm Feb 7, 2023
ac8bfbd
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 7, 2023
3ff9973
remove separate nft query
OzanEm Feb 7, 2023
111cdff
created web3 query
OzanEm Feb 9, 2023
cbe62fe
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 9, 2023
149e64a
updated example md
OzanEm Feb 9, 2023
40608f2
added more data to nftEvm
OzanEm Feb 9, 2023
1ce1b72
added filter by time
OzanEm Feb 9, 2023
57d6114
refactored
OzanEm Feb 10, 2023
7ab508e
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 10, 2023
f105a3c
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 10, 2023
5c07b91
added enum for query returns
OzanEm Feb 13, 2023
a69e3f7
rollback vs code settings
OzanEm Feb 13, 2023
04db323
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 14, 2023
21fd7e6
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 15, 2023
60704a2
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 16, 2023
55bf12d
refactored
OzanEm Feb 16, 2023
6687733
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 16, 2023
133c0bd
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 16, 2023
119c57e
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 20, 2023
57cb019
changed return type of queryPermissionFlag
OzanEm Feb 20, 2023
b327f56
added return type for nft eval
OzanEm Feb 21, 2023
6d06a3a
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 22, 2023
6bfd4ed
updated objects version
OzanEm Feb 22, 2023
df0fdfb
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 23, 2023
ea7827a
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 24, 2023
1f9519e
changed nft holdings address prop to identifier type
OzanEm Feb 24, 2023
e711c1c
Merge branch 'develop' into feat/ENGT-1220
OzanEm Feb 25, 2023
ff29afb
changed type
OzanEm Feb 27, 2023
7fbe397
Merge branch 'develop' into feat/ENGT-1220
OzanEm Mar 1, 2023
62506c1
Merge branch 'develop' into feat/ENGT-1220
OzanEm Mar 2, 2023
f04b487
updated docs
OzanEm Mar 2, 2023
e6a4480
Merge branch 'develop' into feat/ENGT-1220
OzanEm Mar 2, 2023
643d996
Merge branch 'develop' into feat/ENGT-1220
OzanEm Mar 3, 2023
7decf31
updated nft holdings type
OzanEm Mar 5, 2023
3c326ff
updated objects status
OzanEm Mar 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 61 additions & 25 deletions documentation/sdql/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This example checks if the user's age is greater than or equal to 15. It also qu
{
"version": 0.1,
"timestamp": "2021-11-13T20:20:39",
"expiry" : "2022-11-13T20:20:39",
"expiry": "2022-11-13T20:20:39",
"description": "For 15-year and older individuals, querying intractions with the Avalanche blockchain, location, gender, urls visited and chain transaction count",
"business": "Shrapnel",
"queries": {
Expand Down Expand Up @@ -65,17 +65,17 @@ This example checks if the user's age is greater than or equal to 15. It also qu
"name": "gender",
"return": "enum",
"enum_keys": [
"female",
"male",
"nonbinary",
"unknown"
]
"female",
"male",
"nonbinary",
"unknown"
]
},
"q5": {
"name": "url_visited_count",
"return": "object",
"object_schema":{
"patternProperties":{
"object_schema": {
"patternProperties": {
"^http(s)?:\/\/[\\-a-zA-Z0-9]*.[a-zA-Z0-9]*.[a-zA-Z]*\/[a-zA-Z0-9]*$": {
"type": "integer"
}
Expand Down Expand Up @@ -114,6 +114,41 @@ This example checks if the user's age is greater than or equal to 15. It also qu
]
}
}
},
"q7": {
"name": "nft",
"return": "array",
"networkid": "*",
"address": "*",
"array_items": {
"object_schema": {
"properties": {
"networkid": {
"type": "integer",
},
"tokenAddress": {
OzanEm marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"pattern": "^0x[a-fA-F0-9]{40}$",
},
"ticker": {
"type": "string"
},
"balance": {
"type": "number",
},
"decimals": {
"type": "number",
},
},
"required": [
"networkid",
"tokenAddress",
"balance",
"decimals",
"ticker"
],
},
},
}
},
"returns": {
Expand Down Expand Up @@ -147,8 +182,7 @@ This example checks if the user's age is greater than or equal to 15. It also qu
},
"url": "https://418e-64-85-231-39.ngrok.io/insights"
},
"compensations":{

"compensations": {
"parameters": {
"recipientAddress": {
type:...,
Expand All @@ -157,82 +191,84 @@ This example checks if the user's age is greater than or equal to 15. It also qu
"productId": {
type: string,
required: true,
values: [urls]
values: [urls
]
},
"shippingAddress": {
type: string,
required: true,
},

},
"c1":{
"c1": {
"description": "10% discount code for Starbucks",
"chainId": 1,
"callback": {
"parameters": [
"recipientAddress"
],
"data": {...an object to be forwarded with the api call}
"data": {...an object to be forwarded with the api call
}
}
},
"c2":{
"c2": {
"description": "participate in the draw to win a CryptoPunk NFT",
"chainId": 1,
"callback": {
"parameters": [
"recipientAddress",
"productId"
],
"data": {...an object to be forwarded with the api call}
"data": {...an object to be forwarded with the api call
}
}
},
"c3":{
"c3": {
"description": "a free CrazyApesClub NFT",
"chainId": 1,
"callback": {
"parameters": [
"recipientAddress",
"shippingAddress"
],
"data": {...an object to be forwarded with the api call}
"data": {...an object to be forwarded with the api call
}
},
"alternatives": [
"c4",
"c5"
]

},
"c4":{
"c4": {
"description": "a free CrazyApesClub NFT on Avalanche",
"chainId": 43114,
"callback": {
"parameters": [
"recipientAddress",
"shippingAddress"
],
"data": {...an object to be forwarded with the api call}
"data": {...an object to be forwarded with the api call
}
},
"alternatives": [
"c3",
"c5"
]

},
"c5":{
"c5": {
"description": "a free CrazyApesClub NFT on Solana",
"chainId": -1,
"callback": {
"parameters": [
"recipientAddress",
"shippingAddress"
],
"data": {...an object to be forwarded with the api call}
"data": {...an object to be forwarded with the api call
}
},
"alternatives": [
"c3",
"c4"
]

},
},
"logic": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export class ConsentContract implements IConsentContract {
public agreementFlags(
tokenId: TokenId,
): ResultAsync<HexString32, ConsentContractError> {

return ResultAsync.fromPromise(
this.contract.agreementFlagsArray(tokenId) as Promise<HexString32>,
(e) => {
Expand Down Expand Up @@ -512,6 +513,7 @@ export class ConsentContract implements IConsentContract {
public ownerOf(
tokenId: TokenId,
): ResultAsync<EVMAccountAddress, ConsentContractError> {

return ResultAsync.fromPromise(
this.contract.ownerOf(tokenId) as Promise<EVMAccountAddress>,
(e) => {
Expand Down Expand Up @@ -568,10 +570,12 @@ export class ConsentContract implements IConsentContract {
tokenId: TokenId,
): ResultAsync<ConsentToken, ConsentContractError> {
// Get the agreement flags of the user's current consent token
console.log("getting");
OzanEm marked this conversation as resolved.
Show resolved Hide resolved
return ResultUtils.combine([
this.ownerOf(tokenId),
this.agreementFlags(tokenId),
]).andThen(([ownerAddress, agreementFlags]) => {

return okAsync(
new ConsentToken(
this.contractAddress,
Expand Down
25 changes: 19 additions & 6 deletions packages/core/src/implementations/SnickerdoodleCore.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ import {
ConsentTokenUtils,
InvitationService,
MonitoringService,
NetworkQueryEvaluator,
BlockchainTransactionQueryEvaluator,
NftQueryEvaluator,
ProfileService,
QueryEvaluator,
QueryParsingEngine,
QueryRepository,
QueryService,
SiftContractService,
Web3QueryEvaluator,
} from "@core/implementations/business/index.js";
import {
AdContentRepository,
Expand Down Expand Up @@ -119,8 +121,12 @@ import {
IBalanceQueryEvaluatorType,
IConsentTokenUtils,
IConsentTokenUtilsType,
INetworkQueryEvaluator,
INetworkQueryEvaluatorType,
IBlockchainTransactionQueryEvaluator,
IBlockchainTransactionQueryEvaluatorType,
IWeb3QueryEvaluator,
IWeb3QueryEvaluatorType,
INftQueryEvaluator,
INftQueryEvaluatorType,
IQueryEvaluator,
IQueryEvaluatorType,
IQueryParsingEngine,
Expand Down Expand Up @@ -165,7 +171,6 @@ import {
IDataWalletUtilsType,
} from "@core/interfaces/utilities/index.js";


export const snickerdoodleCoreModule = new ContainerModule(
(
bind: interfaces.Bind,
Expand Down Expand Up @@ -278,10 +283,18 @@ export const snickerdoodleCoreModule = new ContainerModule(
.inSingletonScope();

// Query instances
bind<INetworkQueryEvaluator>(INetworkQueryEvaluatorType)
.to(NetworkQueryEvaluator)
bind<IBlockchainTransactionQueryEvaluator>(IBlockchainTransactionQueryEvaluatorType)
.to(BlockchainTransactionQueryEvaluator)
.inSingletonScope();

bind<INftQueryEvaluator>(INftQueryEvaluatorType)
.to(NftQueryEvaluator)
.inSingletonScope();

bind<IWeb3QueryEvaluator>(IWeb3QueryEvaluatorType)
OzanEm marked this conversation as resolved.
Show resolved Hide resolved
.to(Web3QueryEvaluator)
.inSingletonScope();

bind<IQueryEvaluator>(IQueryEvaluatorType)
.to(QueryEvaluator)
.inSingletonScope();
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/implementations/business/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class QueryService implements IQueryService {
consentContractAddress,
)
.andThen(([permittedQueryIds, expectedRewards]) => {

return this.publishSDQLQueryRequestIfExpectedAndEligibleRewardsMatch(
consentToken,
optInKey,
Expand Down Expand Up @@ -265,6 +266,7 @@ export class QueryService implements IQueryService {
this.configProvider.getConfig(),
this.consentTokenUtils.getCurrentConsentToken(consentContractAddress),
]).andThen(([context, config, consentToken]) => {

return this.validateContextConfig(context, consentToken).andThen(() => {
return ResultUtils.combine([
this.queryParsingEngine.handleQuery(
Expand All @@ -277,6 +279,7 @@ export class QueryService implements IQueryService {
context.dataWalletKey!,
),
]).andThen(([maps, optInKey]) => {

const maps2 = maps as [InsightString[], EligibleReward[]];
const insights = maps2[0];
const rewards = maps2[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ export class QueryParsingEngine implements IQueryParsingEngine {
return this.queryFactories
.makeParserAsync(cid, schemaString)
.andThen((sdqlParser) => {

return sdqlParser.buildAST();
})
.andThen((ast: AST) => {

const astEvaluator = this.queryFactories.makeAstEvaluator(
cid,
ast,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import {
PersistenceError,
SDQL_Return,
} from "@snickerdoodlelabs/objects";
import { AST_NetworkQuery } from "@snickerdoodlelabs/query-parser";
import { AST_BlockchainTransactionQuery } from "@snickerdoodlelabs/query-parser";
import { inject, injectable } from "inversify";
import { okAsync, ResultAsync } from "neverthrow";

import { INetworkQueryEvaluator } from "@core/interfaces/business/utilities/query/INetworkQueryEvaluator";
import { IBlockchainTransactionQueryEvaluator } from "@core/interfaces/business/utilities/query/IBlockchainTransactionQueryEvaluator";

@injectable()
export class NetworkQueryEvaluator implements INetworkQueryEvaluator {
export class BlockchainTransactionQueryEvaluator implements IBlockchainTransactionQueryEvaluator {
constructor(
@inject(IDataWalletPersistenceType)
protected dataWalletPersistence: IDataWalletPersistence,
) {}

public eval(
query: AST_NetworkQuery,
query: AST_BlockchainTransactionQuery,
): ResultAsync<SDQL_Return, PersistenceError> {
const result = SDQL_Return(false);
const chainId = query.contract.networkId;
Expand Down Expand Up @@ -93,6 +93,11 @@ export class NetworkQueryEvaluator implements INetworkQueryEvaluator {
});
}


return okAsync(SDQL_Return(false));
}

OzanEm marked this conversation as resolved.
Show resolved Hide resolved



}
Loading