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

[Do Not Merge]: Draft: Update Package Score To Match The Spec #199

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
132 changes: 67 additions & 65 deletions demo/src/network-score-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ async function main() {

const { mnemonic: chainSpaceAdminMnemonic, document: chainSpaceAdminDid } =
await createDid(networkAuthorIdentity)
const chainSpaceAdminKeys = Cord.Utils.Keys.generateKeypairs(chainSpaceAdminMnemonic)
const chainSpaceAdminKeys = Cord.Utils.Keys.generateKeypairs(chainSpaceAdminMnemonic,"sr25519")
console.log(
`🔐 Network Score Admin (${chainSpaceAdminDid.authentication[0].type}): ${chainSpaceAdminDid.uri}`
)
const { mnemonic: networkProviderMnemonic, document: networkProviderDid } =
await createDid(networkAuthorIdentity)
const networkProviderKeys = Cord.Utils.Keys.generateKeypairs(networkProviderMnemonic)
const networkProviderKeys = Cord.Utils.Keys.generateKeypairs(networkProviderMnemonic,"sr25519")
console.log(
`🔐 Network Participant (Provider) (${networkProviderDid.authentication[0].type}): ${networkProviderDid.uri}`
)

const { mnemonic: networkAuthorMnemonic, document: networkAuthorDid } =
await createDid(networkAuthorIdentity)
const networkAuthorKeys = Cord.Utils.Keys.generateKeypairs(networkAuthorMnemonic)
const networkAuthorKeys = Cord.Utils.Keys.generateKeypairs(networkAuthorMnemonic,"sr25519")
console.log(
`🔐 Network Author (API -> Node) (${networkAuthorDid.authentication[0].type}): ${networkAuthorDid.uri}`
)
Expand Down Expand Up @@ -135,34 +135,36 @@ async function main() {
console.log(`\n⏳ Network Rating Transaction Flow`)

console.log(`\n💠 Write Rating - (Genesis) Credit Entry `)
let ratingContent: IRatingContent = {
entityUid: Cord.Utils.UUID.generate(),
entityId: 'Gupta Kirana Store',
providerUid: Cord.Utils.UUID.generate(),
providerId: 'GoFrugal',
entityType: Cord.EntityTypeOf.retail,
ratingType: Cord.RatingTypeOf.overall,
countOfTxn: 100,
totalRating: 320,
let ratingContent: any = {
entity_id: Cord.Utils.UUID.generate(),
entity_name: 'Gupta Kirana Store',
provider_id: 'GoFrugal',
rating_type: Cord.RatingTypeOf.overall,
count_of_txn: 100,
total_rating: 320,
}

console.dir(ratingContent, {
depth: null,
colors: true,
})
const entryDigest = Cord.Utils.Crypto.hashObjectAsHexStr(ratingContent);
const { totalRating, ...restOfRating} = ratingContent;


const entry_digest = Cord.Utils.Crypto.hashObjectAsHexStr(ratingContent);
const { total_rating, ...restOfRating} = ratingContent;

let transformedEntry: IRatingEntry = {
let transformedEntry: Cord.IRatingEntry = {
entry: {
...restOfRating,
providerDid: networkProviderDid.uri.replace('did:cord:', ''),
totalEncodedRating: Math.round(totalRating * 10),
provider_did: networkProviderDid.uri.replace('did:cord:', ''),
total_encoded_rating: Math.round(total_rating * 10),
},
messageId: Cord.Utils.UUID.generate(),
entryDigest,
message_id: Cord.Utils.UUID.generate(),
entry_digest,
};

console.log('166 transformedEntry\n',transformedEntry)

console.log(`\n🌐 Rating Information to API endpoint (/write-ratings) `)
console.dir(transformedEntry, {
depth: null,
Expand Down Expand Up @@ -200,7 +202,7 @@ async function main() {
console.log(`\n💠 Revoke Rating - Debit Entry `)
const revokeInput = {
entryUri: ratingUri,
entityUid: transformedEntry.entry.entityUid,
entity_id: transformedEntry.entry.entity_id,
}
console.dir(revokeInput, {
depth: null,
Expand All @@ -216,14 +218,14 @@ async function main() {

const revokeDigest = Cord.Utils.Crypto.hashObjectAsHexStr(entryTransform)

const revokeRatingEntry: IRatingRevokeEntry = {
const revokeRatingEntry: Cord.IRatingRevokeEntry = {
entry: {
messageId: msgId,
entryDigest: revokeDigest,
referenceId: ratingUri,
message_id: msgId,
entry_digest: revokeDigest,
reference_id: ratingUri,
},
entityUid: transformedEntry.entry.entityUid,
providerDid: networkProviderDid.uri,
entity_id: transformedEntry.entry.entity_id,
provider_did: networkProviderDid.uri,
}

console.log(
Expand Down Expand Up @@ -268,10 +270,10 @@ async function main() {

let revisedRatingContent = {
...ratingContent,
providerDid: transformedEntry.entry.providerDid,
referenceId: revokedRatingUri,
countOfTxn: 80,
totalRating: 280,
provider_did: transformedEntry.entry.provider_did,
reference_id: revokedRatingUri,
count_of_txn: 80,
total_rating: 280,
}

console.dir(revisedRatingContent, {
Expand All @@ -284,15 +286,15 @@ async function main() {
let transformedRevisedEntry = {
entry: {
...revisedRatingContent,
referenceId: revokedRatingUri,
totalEncodedRating: Math.round(revisedRatingContent.totalRating * 10),
reference_id: revokedRatingUri,
total_encoded_rating: Math.round(revisedRatingContent.total_rating * 10),
},
messageId: Cord.Utils.UUID.generate(),
referenceId: revokedRatingUri,
entryDigest: revisedEntryDigest,
message_id: Cord.Utils.UUID.generate(),
reference_id: revokedRatingUri,
entry_digest: revisedEntryDigest,
};

delete transformedRevisedEntry.entry.totalRating;
delete transformedRevisedEntry.entry.total_rating;

console.log(
`\n🌐 Rating Revised(Credit) Information to API endpoint (/write-ratings)\n`
Expand Down Expand Up @@ -329,35 +331,35 @@ async function main() {
console.log(`\n🚫 Revision Anchoring failed! " 🚫`)
}

console.log(`\n🌐 Query From Chain - Rating Entry `)
const ratingEntryFromChain = await Cord.Score.fetchRatingDetailsfromChain(
revisedRatingUri,
'Asia/Kolkata'
)
console.dir(ratingEntryFromChain, {
depth: null,
colors: true,
})

console.log(`\n🌐 Query From Chain - Aggregate Score `)
const aggregateScoreFromChain =
await Cord.Score.fetchEntityAggregateScorefromChain(
ratingContent.entityUid,
Cord.RatingTypeOf.overall
)
console.dir(aggregateScoreFromChain, {
depth: null,
colors: true,
})

console.log(`\n🌐 Query From Chain - Chain Space Usage `)
const spaceUsageFromChain = await Cord.ChainSpace.fetchFromChain(
chainSpace.uri
)
console.dir(spaceUsageFromChain, {
depth: null,
colors: true,
})
// console.log(`\n🌐 Query From Chain - Rating Entry `)
// const ratingEntryFromChain = await Cord.Score.fetchRatingDetailsfromChain(
// revisedRatingUri,
// 'Asia/Kolkata'
// )
// console.dir(ratingEntryFromChain, {
// depth: null,
// colors: true,
// })

// console.log(`\n🌐 Query From Chain - Aggregate Score `)
// const aggregateScoreFromChain =
// await Cord.Score.fetchEntityAggregateScorefromChain(
// ratingContent.entity_id,
// Cord.RatingTypeOf.overall
// )
// console.dir(aggregateScoreFromChain, {
// depth: null,
// colors: true,
// })

// console.log(`\n🌐 Query From Chain - Chain Space Usage `)
// const spaceUsageFromChain = await Cord.ChainSpace.fetchFromChain(
// chainSpace.uri
// )
// console.dir(spaceUsageFromChain, {
// depth: null,
// colors: true,
// })
}
main()
.then(() => console.log('\nBye! 👋 👋 👋 '))
Expand Down
2 changes: 1 addition & 1 deletion packages/augment-api/metadata/cord.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/augment-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:ts": "tsc -p tsconfig.build.json",
"generate:defs": "tsx ../../node_modules/.bin/polkadot-types-from-defs --package @cord.network/augment-api --input ./src/interfaces --endpoint ./metadata/cord.json",
"generate:meta": "tsx ../../node_modules/.bin/polkadot-types-from-chain --package @cord.network/augment-api --endpoint ./metadata/cord.json --output ./src/interfaces --strict",
"update-metadata": "node ./scripts/fetchMetadata.cjs -o './metadata/cord.json' -e 'wss://staging.cord.network/'"
"update-metadata": "node ./scripts/fetchMetadata.cjs -o './metadata/cord.json' -e 'ws://127.0.0.1:9944'"
},
"repository": "github:dhiway/cord.js",
"engines": {
Expand Down
22 changes: 16 additions & 6 deletions packages/augment-api/src/interfaces/augment-api-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,27 @@ declare module '@polkadot/api-base/types/consts' {
maxEventsHistory: u32 & AugmentedConst<ApiType>;
};
identity: {
/**
* Maximum number of additional fields that may be stored in an ID.
* Needed to bound the I/O required to access an identity, but can be
* pretty high.
**/
maxAdditionalFields: u32 & AugmentedConst<ApiType>;
/**
* Maxmimum number of registrars allowed in the system. Needed to bound
* the complexity of, e.g., updating judgements.
**/
maxRegistrars: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of sub-accounts allowed per identified account.
**/
maxSubAccounts: u32 & AugmentedConst<ApiType>;
/**
* The maximum length of a suffix.
**/
maxSuffixLength: u32 & AugmentedConst<ApiType>;
/**
* The maximum length of a username, including its suffix and any system-added delimiters.
**/
maxUsernameLength: u32 & AugmentedConst<ApiType>;
/**
* The number of blocks within which a username grant must be accepted.
**/
pendingUsernameExpiration: u32 & AugmentedConst<ApiType>;
};
imOnline: {
/**
Expand Down
48 changes: 48 additions & 0 deletions packages/augment-api/src/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,22 @@ declare module '@polkadot/api-base/types/errors' {
* Invalid judgement.
**/
InvalidJudgement: AugmentedError<ApiType>;
/**
* The signature on a username was not valid.
**/
InvalidSignature: AugmentedError<ApiType>;
/**
* The provided suffix is too long.
**/
InvalidSuffix: AugmentedError<ApiType>;
/**
* The target is invalid.
**/
InvalidTarget: AugmentedError<ApiType>;
/**
* The username does not meet the requirements.
**/
InvalidUsername: AugmentedError<ApiType>;
/**
* The provided judgement was for a different identity.
**/
Expand All @@ -558,10 +570,18 @@ declare module '@polkadot/api-base/types/errors' {
* Error that occurs when there is an issue paying for judgement.
**/
JudgementPaymentFailed: AugmentedError<ApiType>;
/**
* The authority cannot allocate any more usernames.
**/
NoAllocation: AugmentedError<ApiType>;
/**
* No identity found.
**/
NoIdentity: AugmentedError<ApiType>;
/**
* The username cannot be forcefully removed because it can still be accepted.
**/
NotExpired: AugmentedError<ApiType>;
/**
* Account isn't found.
**/
Expand All @@ -570,6 +590,22 @@ declare module '@polkadot/api-base/types/errors' {
* Account isn't named.
**/
NotNamed: AugmentedError<ApiType>;
/**
* Sub-account isn't owned by sender.
**/
NotOwned: AugmentedError<ApiType>;
/**
* Sender is not a sub-account.
**/
NotSub: AugmentedError<ApiType>;
/**
* The sender does not have permission to issue a username.
**/
NotUsernameAuthority: AugmentedError<ApiType>;
/**
* The requested username does not exist.
**/
NoUsername: AugmentedError<ApiType>;
/**
* Registrar already exists.
**/
Expand All @@ -578,6 +614,10 @@ declare module '@polkadot/api-base/types/errors' {
* Registrar not found.
**/
RegistrarNotFound: AugmentedError<ApiType>;
/**
* Setting this username requires a signature, but none was provided.
**/
RequiresSignature: AugmentedError<ApiType>;
/**
* Sticky judgement.
**/
Expand All @@ -590,6 +630,14 @@ declare module '@polkadot/api-base/types/errors' {
* Maximum amount of registrars reached. Cannot add any more.
**/
TooManyRegistrars: AugmentedError<ApiType>;
/**
* Too many subs-accounts.
**/
TooManySubAccounts: AugmentedError<ApiType>;
/**
* The username is already taken.
**/
UsernameTaken: AugmentedError<ApiType>;
};
imOnline: {
/**
Expand Down
Loading
Loading