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

Non Fungible Token policies and guards (Feat) #1986

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3433721
feat: created nft policy object and added it to nft object
nil-amrutlal Apr 18, 2024
f240bba
fix: fixed naming of object types
nil-amrutlal Apr 18, 2024
cff5fd2
chore: renamed some files and functions to more accurate naming
nil-amrutlal Apr 19, 2024
b990dad
feat: implemented nft info data loader
nil-amrutlal Apr 19, 2024
cc0ce43
wip: implemented retry and object mapping as well as aux functions
nil-amrutlal Apr 22, 2024
5935564
style: lint fixes
nil-amrutlal Apr 22, 2024
826e935
fix: remove unecessary code
nil-amrutlal Apr 22, 2024
dae7ecb
feat: replaced custom code with get policy info and fixed policies
nil-amrutlal Apr 23, 2024
288dcad
chore: changeset file
nil-amrutlal Apr 24, 2024
08b2e50
feat: add error handling for socket hanging up
nil-amrutlal Apr 25, 2024
1ecc74f
feat: add json strings, change guards, add keysets, module references…
nil-amrutlal Apr 25, 2024
7b5c8a1
feat: ajust functions to return correct types
nil-amrutlal Apr 25, 2024
74c524b
Merge commit '37375fa7ed9cf06a99c68ab403320f00de3e66b8' into feat/gra…
nil-amrutlal Apr 26, 2024
b7659a3
feat: client changes to accomodate graph schema changes
nil-amrutlal Apr 29, 2024
60db032
style: lint fixes
nil-amrutlal Apr 29, 2024
36c54d0
fix: testing to see if build restarts
nil-amrutlal Apr 29, 2024
223096d
fix: style fix (attempting build pass)
nil-amrutlal Apr 29, 2024
1b39414
chore: formatting
Ghislain89 Apr 29, 2024
af5048d
fix: e2e testing
nil-amrutlal Apr 29, 2024
1c75595
Merge commit 'b96c16be311a3c66f8b479af2c487a7cda937a4b' into feat/gra…
nil-amrutlal May 2, 2024
37b01b8
feat: made some adjustments to the guard object for non-fungibles wit…
nil-amrutlal May 2, 2024
a059efe
fix: typing issue
nil-amrutlal May 2, 2024
31a258d
feat: restructure Ikeyset assignation in chain accounts
nil-amrutlal May 2, 2024
0d2f3a2
Merge commit '9ba191f1b66e6dd7fb11ad27b3b4bb19008b025e' into feat/gra…
nil-amrutlal May 8, 2024
f64e020
feat: update graph schema
nil-amrutlal May 8, 2024
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
6 changes: 6 additions & 0 deletions .changeset/big-pots-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kadena/graph': patch
---

Add policies to non fungible token; restructure the guards and create JsonString
object
5 changes: 5 additions & 0 deletions .changeset/three-rules-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/graph-client': patch
---

Adjusted client to changes made in graph schema for Guards and Policies
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ export const FungibleChainAccountTable = (
{chainAccount.balance}
</Link>
</Cell>
<Cell>{chainAccount.guard.predicate}</Cell>
<Cell>{chainAccount.guard.keys.join(', ')}</Cell>
<Cell>
{chainAccount.guard.__typename === 'Keyset' ? (
chainAccount.guard.predicate
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
<Cell>
{chainAccount.guard.__typename === 'Keyset' ? (
chainAccount.guard.keys.join(', ')
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
</Row>
))}
</TableBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ export const TokenTable = (props: ITokenTableProps): JSX.Element => {
<Cell>{token.tokenId}</Cell>
<Cell>{token.chainId}</Cell>
<Cell>{token.balance}</Cell>

<Cell>
<strong>Predicate:</strong> {token.guard.predicate}
<br />
<strong>Keys:</strong> {token.guard.keys.join(', ')}
{token.guard.__typename === 'Keyset' ? (
<>
<strong>Predicate:</strong> {token.guard.predicate}
<br />
<strong>Keys:</strong> {token.guard.keys.join(', ')}
</>
) : token.guard.__typename === 'JsonString' ? (
<>
<strong>Guard:</strong> {token.guard.value}
</>
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
</Row>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const ALL_FUNGIBLE_CHAIN_ACCOUNT_FIELDS: DocumentNode = gql`
...CoreFungibleChainAccountFields
accountName
guard {
keys
predicate
... on Keyset {
keys
predicate
}
}
fungibleName

Expand Down
24 changes: 16 additions & 8 deletions packages/apps/graph-client/src/graphql/queries.graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export const getBlockFromHash: DocumentNode = gql`
}
minerAccount {
guard {
predicate
keys
... on Keyset {
predicate
keys
}
}
}
parent {
Expand Down Expand Up @@ -88,8 +90,10 @@ export const getFungibleAccount: DocumentNode = gql`
chainAccounts {
...CoreFungibleChainAccountFields
guard {
keys
predicate
... on Keyset {
keys
predicate
}
}
}
transactions {
Expand Down Expand Up @@ -337,8 +341,10 @@ export const getNonFungibleAccount: DocumentNode = gql`
tokenId
chainId
guard {
predicate
keys
... on Keyset {
predicate
keys
}
}
}
transactions {
Expand All @@ -364,8 +370,10 @@ export const getNonFungibleChainAccount: DocumentNode = gql`
tokenId
chainId
guard {
predicate
keys
... on Keyset {
predicate
keys
}
}
}
transactions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,29 @@ const ChainAccount: React.FC = () => {
<strong>Guard Predicate</strong>
</Cell>
<Cell>
{
{fungibleChainAccountData.fungibleChainAccount.guard
.__typename === 'Keyset' ? (
fungibleChainAccountData.fungibleChainAccount.guard
.predicate
}
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
</Row>
<Row>
<Cell>
<strong>Guard Keys</strong>
</Cell>
<Cell>
{fungibleChainAccountData.fungibleChainAccount.guard.keys}
<Cell>
{fungibleChainAccountData.fungibleChainAccount.guard
.__typename === 'Keyset' ? (
fungibleChainAccountData.fungibleChainAccount.guard
.keys
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
</Cell>
</Row>
</TableBody>
Expand Down
26 changes: 19 additions & 7 deletions packages/apps/graph-client/src/pages/block/overview/[hash].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,17 @@ const Block: React.FC = () => {
<Column>Value</Column>
</TableHeader>
<TableBody>
{data.block.minerAccount.guard.keys?.map(
(minerKey, index) => (
<Row key={index}>
<Cell>{minerKey}</Cell>
</Row>
),
{data.block.minerAccount.guard.__typename ===
'Keyset' ? (
data.block.minerAccount.guard.keys?.map(
(minerKey, index) => (
<Row key={index}>
<Cell>{minerKey}</Cell>
</Row>
),
)
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</TableBody>
</Table>
Expand All @@ -217,7 +222,14 @@ const Block: React.FC = () => {
<Cell>
<strong>Predicate</strong>
</Cell>
<Cell>{data.block.minerAccount.guard.predicate}</Cell>
<Cell>
{data.block.minerAccount.guard.__typename ===
'Keyset' ? (
data.block.minerAccount.guard.predicate
) : (
<span style={{ color: 'lightgray' }}>N/A</span>
)}
</Cell>
</Row>
</TableBody>
</Table>
Expand Down
40 changes: 31 additions & 9 deletions packages/apps/graph/generated-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,17 @@ type GraphConfiguration {
minimumBlockHeight: BigInt
}

"""A guard"""
union Guard = JsonString | Keyset

"""A JSON string."""
type JsonString {
type: String!
value: String!
}

"""Guard for an account."""
type Guard {
type Keyset {
keys: [String!]!
predicate: String!
}
Expand All @@ -226,6 +235,12 @@ type MinerKey implements Node {
key: String!
}

"""A reference to a module."""
type ModuleReference {
name: String!
namespace: String!
}

"""Information about the network."""
type NetworkInfo {
"""The version of the API."""
Expand Down Expand Up @@ -302,25 +317,26 @@ type NonFungibleChainAccountTransactionsConnectionEdge {
node: Transaction!
}

"""Information related to a token."""
type NonFungibleToken {
precision: Int!
supply: Int!
uri: String!
}

"""The token identifier and its balance."""
type NonFungibleTokenBalance implements Node {
accountName: String!
balance: Int!
chainId: String!
guard: Guard!
id: ID!
info: NonFungibleToken
info: NonFungibleTokenInfo
tokenId: String!
version: String!
}

"""Information related to a token."""
type NonFungibleTokenInfo {
policies: [Policy!]!
precision: Int!
supply: Int!
uri: String!
}

input PactQuery {
chainId: String!
code: String!
Expand Down Expand Up @@ -348,6 +364,12 @@ type PageInfo {
startCursor: String
}

"""A policy that defines the rules for a non-fungible token."""
type Policy {
refName: ModuleReference!
refSpec: [ModuleReference!]!
}

"""Floats that will have a value greater than 0."""
scalar PositiveFloat

Expand Down
24 changes: 15 additions & 9 deletions packages/apps/graph/src/devnet/deployment/marmalade/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ export async function deployMarmaladeContracts(
nsDestinationPath: string = marmaladeLocalConfig.namespacePath,
): Promise<void> {
logger.info('Validating repository data...');
validateConfig(
marmaladeRepository,
marmaladeLocalConfig,
marmaladeRemoteConfig,
);
if (
!validateConfig(
marmaladeRepository,
marmaladeLocalConfig,
marmaladeRemoteConfig,
)
) {
throw new Error('Invalid repository data');
}

logger.info('Preparing directories...');
await handleDirectorySetup(
Expand Down Expand Up @@ -362,8 +366,10 @@ export function validateConfig(
repositoryConfig: IMarmaladeRepository,
localConfig: IMarmaladeLocalConfig,
remoteConfig: IMarmaladeRemoteConfig,
): void {
validateObjectProperties(repositoryConfig, 'Repository');
validateObjectProperties(localConfig, 'Local');
validateObjectProperties(remoteConfig, 'Remote');
): boolean {
return (
validateObjectProperties(repositoryConfig, 'Repository') &&
validateObjectProperties(localConfig, 'Local') &&
validateObjectProperties(remoteConfig, 'Remote')
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ITokenInfo {
precision: number;
uri: string;
id: string;
policies: { moduleName: string }[];
}

export const getTokenInfo = async (
Expand Down Expand Up @@ -97,5 +98,15 @@ export const getTokenInfo = async (
}
}

if ('policies' in tokenInfo) {
if (!Array.isArray(tokenInfo.policies)) {
tokenInfo.policies = tokenInfo.policies.map((policy: string) => ({
moduleName: policy,
}));
}
} else if ('policy' in tokenInfo) {
tokenInfo.policies = { moduleName: tokenInfo.policy.toString() };
}

return tokenInfo as ITokenInfo;
};
14 changes: 10 additions & 4 deletions packages/apps/graph/src/graph/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import type {
IFungibleChainAccount,
IGasLimitEstimation,
IGraphConfiguration,
IGuard,
IJsonString,
IKeyset,
IModuleReference,
INetworkInfo,
INonFungibleAccount,
INonFungibleChainAccount,
INonFungibleToken,
INonFungibleTokenBalance,
INonFungibleTokenInfo,
IPactQueryResponse,
IPolicy,
ITransactionCapability,
ITransactionCommand,
ITransactionMempoolInfo,
Expand Down Expand Up @@ -80,11 +83,11 @@ export const builder = new SchemaBuilder<
FungibleChainAccount: IFungibleChainAccount;
GasLimitEstimation: IGasLimitEstimation;
GraphConfiguration: IGraphConfiguration;
Guard: IGuard;
Keyset: IKeyset;
NonFungibleAccount: INonFungibleAccount;
NonFungibleChainAccount: INonFungibleChainAccount;
NonFungibleTokenBalance: INonFungibleTokenBalance;
NonFungibleToken: INonFungibleToken;
NonFungibleTokenInfo: INonFungibleTokenInfo;
TransactionMeta: ITransactionMeta;
ExecutionPayload: IExecutionPayload;
ContinuationPayload: IContinuationPayload;
Expand All @@ -94,6 +97,9 @@ export const builder = new SchemaBuilder<
TransactionCapability: ITransactionCapability;
TransactionSignature: ITransactionSignature;
PactQueryResponse: IPactQueryResponse;
Policy: IPolicy;
ModuleReference: IModuleReference;
JsonString: IJsonString;
NetworkInfo: INetworkInfo;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IFungibleChainAccountDetails } from '@services/chainweb-node/fungible-account-details';
import { getFungibleAccountDetails } from '@services/chainweb-node/fungible-account-details';
import { getFungibleAccountDetailsWithRetry } from '@services/chainweb-node/fungible-account-details';
import DataLoader from 'dataloader';

interface IFungibleAccountDetailsKey {
Expand All @@ -14,7 +14,7 @@ export const fungibleAccountDetailsLoader = new DataLoader<
>(async (keys: readonly IFungibleAccountDetailsKey[]) => {
const results = await Promise.all(
keys.map(({ fungibleName, accountName, chainId }) =>
getFungibleAccountDetails(fungibleName, accountName, chainId),
getFungibleAccountDetailsWithRetry(fungibleName, accountName, chainId),
),
);

Expand Down
Loading