-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from cardanoapi/enhancement/refactor-metadata…
…-and-context Enhancement/refactor metadata and context
- Loading branch information
Showing
19 changed files
with
400 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,23 @@ | ||
import { FunctionContext } from '../executor/BaseFunction' | ||
import { rewardAddressBech32 } from '../utils/cardano' | ||
import * as blake from 'blakejs' | ||
|
||
export default async function handler( | ||
context: FunctionContext, | ||
anchor: Record<string, any> | ||
) { | ||
const metadata = JSON.stringify(generateProposalMetadata(context.agentName)) | ||
const hash = blake.blake2bHex(metadata, undefined, 32) | ||
const url = await context.builtins.saveMetadata(hash, metadata) | ||
const rewardAddress = rewardAddressBech32( | ||
0, | ||
context.wallet.stakeKey.pubKeyHash | ||
const { dataHash, url } = await context.builtins.saveMetadata( | ||
context.helpers.generateProposalMetadataContent() | ||
) | ||
const anchorData = | ||
anchor['url'] && anchor['dataHash'] ? anchor : { url, dataHash } | ||
const req = { | ||
proposals: [ | ||
{ | ||
refundAccount: rewardAddress, | ||
anchor: anchor || { | ||
url, | ||
dataHash: hash, | ||
}, | ||
refundAccount: context.wallet.rewardAddress, | ||
anchor: anchorData, | ||
}, | ||
], | ||
} | ||
return await context.wallet.buildAndSubmit(req).catch((e) => { | ||
throw e | ||
}) | ||
} | ||
function generateProposalMetadata(agentName: string) { | ||
return { | ||
'@context': { | ||
CIP100: 'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#', | ||
CIP108: 'https://github.com/cardano-foundation/CIPs/blob/master/CIP-0108/README.md#', | ||
hashAlgorithm: 'CIP100:hashAlgorithm', | ||
body: { | ||
'@id': 'CIP108:body', | ||
'@context': { | ||
references: { | ||
'@id': 'CIP108:references', | ||
'@container': '@set', | ||
'@context': { | ||
GovernanceMetadata: | ||
'CIP100:GovernanceMetadataReference', | ||
Other: 'CIP100:OtherReference', | ||
label: 'CIP100:reference-label', | ||
uri: 'CIP100:reference-uri', | ||
referenceHash: { | ||
'@id': 'CIP108:referenceHash', | ||
'@context': { | ||
hashDigest: 'CIP108:hashDigest', | ||
hashAlgorithm: 'CIP100:hashAlgorithm', | ||
}, | ||
}, | ||
}, | ||
}, | ||
title: 'CIP108:title', | ||
abstract: 'CIP108:abstract', | ||
motivation: 'CIP108:motivation', | ||
rationale: 'CIP108:rationale', | ||
}, | ||
}, | ||
authors: { | ||
'@id': 'CIP100:authors', | ||
'@container': '@set', | ||
'@context': { | ||
name: 'http://xmlns.com/foaf/0.1/name', | ||
witness: { | ||
'@id': 'CIP100:witness', | ||
'@context': { | ||
witnessAlgorithm: 'CIP100:witnessAlgorithm', | ||
publicKey: 'CIP100:publicKey', | ||
signature: 'CIP100:signature', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
authors: [], | ||
hashAlgorithm: 'blake2b-256', | ||
body: { | ||
abstract: `This proposal is created automatically by agent: ${agentName}`, | ||
motivation: | ||
'This proposal is automatically generated by autonomous-agent-testing', | ||
references: [ | ||
{ | ||
'@type': 'Other', | ||
label: 'autonomous-agent-testing', | ||
uri: 'https://cardanoapi.github.io/autonomous-agents/archietecture_docusaurus/docs/architecture', | ||
}, | ||
], | ||
title: 'Automated Proposal by AAT', | ||
}, | ||
} | ||
} |
Oops, something went wrong.