Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Jul 13, 2024
1 parent 8fd27ac commit 0bc7e39
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 72 deletions.
2 changes: 0 additions & 2 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ type RainMetaV1 @entity {
id: Bytes! # Include the RainMeta MagicNumber.
"Original meta bytes directly emitted from the contract"
metaBytes: Bytes! # Original meta bytes emitted from the contract
"The meta content V1 decoded from the meta bytes emitted"
content: [ContentMetaV1!]!
}

type ContentMetaV1 @entity {
Expand Down
69 changes: 0 additions & 69 deletions subgraph/src/orderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,73 +864,4 @@ export function handleMetaV1(event: MetaV1): void {
order.save();
}
}

// Converts the emitted target from Bytes to a Hexadecimal value
let meta = event.params.meta.toHex();

// Decode the meta only if incluse the RainMeta magic number.
if (meta.includes(MagicNumbers.RAIN_META_DOCUMENT)) {
meta = meta.replace(MagicNumbers.RAIN_META_DOCUMENT, "");
const data = new CBORDecoder(hexStringToArrayBuffer(meta));
const res = data.parse();

// Auxiliar for MetaV1.content
const auxContent = metaV1.content;

const contentArr: ContentMeta[] = [];

if (res.isSequence) {
const dataString = res.toString();
const jsonArr = json.fromString(dataString).toArray();
for (let i = 0; i < jsonArr.length; i++) {
const jsonValue = jsonArr[i];

// if some value is not a JSON/Map, then is not following the RainMeta design.
// So, return here to avoid assignation.
if (jsonValue.kind != JSONValueKind.OBJECT) return;

const jsonContent = jsonValue.toObject();

// If some content is not valid, then skip it since is bad formed
if (!ContentMeta.validate(jsonContent)) return;

const content = new ContentMeta(jsonContent, metaV1.id);
contentArr.push(content);
}
} else if (res.isObj) {
const dataString = res.toString();
const jsonObj = json.fromString(dataString).toObject();

if (!ContentMeta.validate(jsonObj)) return;
const content = new ContentMeta(jsonObj, metaV1.id);
contentArr.push(content);
//
} else {
// If the response is NOT a Sequence or an Object, then the meta have an
// error or it's bad formed.
// In this case, we skip to continue the decoding and assignation process.
return;
}

for (let i = 0; i < contentArr.length; i++) {
const metaContent = contentArr[i].generate();

// This include each meta content on the RainMeta related
if (!auxContent.includes(metaContent.id)) {
auxContent.push(metaContent.id);
}
}

// Saving
for (let i = 0; i < contentArr.length; i++) {
contentArr[i].saveMeta();
}

metaV1.content = auxContent;
metaV1.save();
} else {
// The meta emitted does not include the RainMeta magic number, so does not
// follow the RainMeta Desing
return;
}
}
1 change: 0 additions & 1 deletion subgraph/src/utils/entity/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function getRainMetaV1(meta: Bytes): RainMetaV1 {
if (!metaV1) {
metaV1 = new RainMetaV1(metaV1_ID);
metaV1.metaBytes = meta;
metaV1.content = [];
metaV1.save();
}

Expand Down

0 comments on commit 0bc7e39

Please sign in to comment.