Skip to content

dispatchRatingToChain

dispatchRatingToChain(ratingEntry, authorAccount, authorizationUri, signCallback): Promise<RatingEntryUri>

Dispatches a rating entry to the blockchain.

This asynchronous function is responsible for dispatching a rating entry to the blockchain. It first checks if the rating entry already exists on the blockchain. If it does, the function simply returns the existing entry’s URI. If the rating entry is not already stored, the function proceeds to dispatch it to the blockchain. This involves creating and signing a transaction to register the rating, and then submitting this transaction to the blockchain. The function is essential for ensuring that ratings are correctly and securely recorded in the blockchain environment.

Parameters

ratingEntry: IRatingDispatch

The rating entry object that needs to be dispatched. This includes the entry’s details and its unique URI.

authorAccount: CordKeyringPair

The blockchain account of the author, used for signing the transaction.

authorizationUri: auth:cord:${string}

The URI that provides authorization context for the rating entry dispatch.

signCallback: SignExtrinsicCallback

A callback function for signing the extrinsic (blockchain transaction).

Returns

Promise<RatingEntryUri>

  • A promise that resolves to the URI of the rating entry. If the entry was already on the chain, it returns the existing URI.

Throws

  • Thrown if there’s an error during the dispatch process, such as issues with signing, transaction creation, or submission.

Example

// Example usage of the function
const ratingEntry = {
// ... rating entry properties ...
};
const authorAccount = { /* ... author's blockchain account ... */ };
const authorizationUri = 'authUri123';
const signCallback = async (/* ... parameters ... */) => { /* ... signing logic ... */ };
try {
const entryUri = await dispatchRatingToChain(ratingEntry, authorAccount, authorizationUri, signCallback);
console.log('Dispatched Rating Entry URI:', entryUri);
} catch (error) {
console.error('Error dispatching rating to chain:', error);
}

Source

network-score/src/Scoring.chain.ts:140