Skip to content

Commit

Permalink
Add blueprint to extract soundxyz artists
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Sep 5, 2022
1 parent 6d3258a commit 029d4cb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/call-block-logs-with-soundxyz-artists.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { readFileSync } from "fs";
import { resolve } from "path";
import { env } from "process";

const platformAddresses = {
"0xabefbc9fd2f806065b4f3c237d4b59d9a97bcac7": {
name: "zora",
},
"0x0bc2a24ce568dad89691116d5b34deb6c203f342": {
name: "catalog",
version: "2.0.0",
},
"0xf5819e27b9bad9f97c177bf007c1f96f26d91ca6": {
name: "noizd",
},
"0x2b5426a5b98a3e366230eba9f95a24f09ae4a584": {
name: "mintsongs",
version: "2.0.0",
},
};

export function ingestFile(name, mainObj = {}) {
// NOTE: We don't want this function to have side effects as e.g. mutating
// `mainObj`'s properties which is why we copy it.
let copyObj = { ...mainObj };
const content = readFileSync(resolve(env.DATA_DIR, name)).toString();
const lines = content.split("\n").filter((line) => !!line);

for (const line of lines) {
const pLine = JSON.parse(line);
copyObj = { ...copyObj, ...pLine };
}

return copyObj;
}

export default {
name: "call-block-logs",
transformer: {
args: [
ingestFile("soundxyz-filter-contracts-transformation", platformAddresses),
],
},
};
18 changes: 18 additions & 0 deletions test/call-block-logs-with-sound-artists_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from "ava";

import { ingestFile } from "../src/call-block-logs-with-soundxyz-artists.mjs";

test("if ingesting files can yield main object", (t) => {
process.env.DATA_DIR = "./test/fixtures";
let mainObj = { hello: "world" };
const result = ingestFile(
"soundxyz-filter-contracts-transformation",
mainObj
);
t.deepEqual(mainObj, { hello: "world" });
t.deepEqual(result, {
"0xca13eaa6135d719e743ffebb5c26de4ce2f9600c": { name: "sound" },
"0xb8dfff430eb204eeeae713a9d4642352e3df6887": { name: "sound" },
hello: "world",
});
});
2 changes: 2 additions & 0 deletions test/fixtures/soundxyz-filter-contracts-transformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"0xca13eaa6135d719e743ffebb5c26de4ce2f9600c":{"name":"sound"}}
{"0xb8dfff430eb204eeeae713a9d4642352e3df6887":{"name":"sound"}}

0 comments on commit 029d4cb

Please sign in to comment.