testing clarity and commented alternate CID generation

This commit is contained in:
Michael Shaw 2023-01-19 16:18:19 -05:00
parent 49ebd1ab65
commit 42230659c1
4 changed files with 20 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
dist
.env
.idea/

View File

@ -75,12 +75,10 @@ export const parseMsgSetRecordResponse = (data: string) => {
const responseBytes = Buffer.from(data, 'hex')
// TODO: Decode response using protobuf.
// const msgSetRecordResponse = nameserviceTx.vulcanize.nameservice.v1beta1.MsgSetRecordResponse.deserialize(responseBytes);
// const msgSetRecordResponse = registryTx.vulcanize.registry.v1beta1.MsgSetRecordResponse.deserialize(responseBytes);
// return msgSetRecordResponse.toObject();
// Workaround as proto based decoding is not working.
const [_, id] = responseBytes.toString().split(';')
return { id }
}

View File

@ -25,7 +25,7 @@ const utilTests = () => {
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
// Create watcher.
watcher = await getBaseConfig(WATCHER_YML_PATH);
watcher = await getBaseConfig(WATCHER_YML_PATH); //this overwrites version to 0.0.1
const result = await registry.setRecord(
{
privateKey,

View File

@ -2,6 +2,8 @@ import * as Block from 'multiformats/block'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as dagCBOR from '@ipld/dag-cbor'
import * as dagJSON from '@ipld/dag-json'
//import { CID } from 'multiformats/cid'
//import * as json from 'multiformats/codecs/json'
/**
* Utils
@ -86,15 +88,29 @@ export class Util {
* Get record content ID.
*/
static async getContentId(record: any) {
//this encode/decode does nothing, afaict
const serialized = dagJSON.encode(record)
const recordData = dagJSON.decode(serialized)
//these are for version 0.0.1 of watcher.yml test data:
//const dside = {"build_artifact_cid":"QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9","repo_registration_record_cid":"QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D","tls_cert_cid":"QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR","type":"WebsiteRegistrationRecord","url":"https://cerc.io","version":"0.0.1"}
//bafyreiek4hnoqmits66bjyxswapplweuoqe4en2ux6u772o4y3askpd3ny is the CBOR encoding w/ sha 256 hasher
//bafyreifalhff7dp6o4hd573b5zdbbnl2wml5q2nrms474lrzp7dgptwxkm is expected DAG-CBOR w/ sha 256 hasher
//bafyreihpfkdvib5muloxlj5b3tgdwibjdcu3zdsuhyft33z7gtgnlzlkpm is CBOR??? encoding of empty json payload.
const block = await Block.encode({
value: recordData,
codec: dagCBOR,
hasher
})
//manual CID construction
//const dbytes = dagCBOR.encode(dside)
//console.log("BYTES: " + dbytes)
//const hash = await hasher.digest(dbytes)
//console.log("HASH: " + hash)
//const cid = CID.create(1, dagCBOR.code, hash)
//console.log("TEST CID: " + cid.toString())
return block.cid.toString();
}
}