Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat, Search #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The content of the file should be like this:

```JSON
{
"address": "0xADDRESS",
"labels": [{ "type": "info", "value": "LlamaFolio" }],
"links": {
"twitter": "https://twitter.com/llamafolio"
Expand Down
46 changes: 46 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Label {
type SocialLabel = "twitter" | "telegram" | "github";

export interface AddressLabels {
address: string
labels: Label[];
links: { [k in SocialLabel]: string };
}
Expand All @@ -41,6 +42,7 @@ export function getLabel(address: string, ensName?: string): AddressLabels {
const registryLabels = registry[address];

const labelt = {
address,
links: registryLabels?.links ?? {},
labels: registryLabels?.labels ?? [],
};
Expand All @@ -60,3 +62,47 @@ export function getLabel(address: string, ensName?: string): AddressLabels {

return labelt;
}

const searchRegistry: Array<AddressLabels> = (function() {
const requireContext = require.context("./labels", false, /.json$/);
const keys = requireContext.keys();
const values = keys.map(requireContext) as Array<AddressLabels>

return values
})()


export interface SearchLabels extends Omit<AddressLabels, 'links'> {
links: Array<{ name: SocialLabel, value: string }>
}

/**
* @param address lowercase string. ex: "founder"
*/
export function searchLabel(searchTerm: string): Array<SearchLabels> {
const results = searchRegistry.map(addressLabels => {
const labels = addressLabels.labels.filter(label => label.value.toLowerCase().includes(searchTerm))

const links = (Object.keys(addressLabels.links) as Array<SocialLabel>).reduce((acc, key) => {
const socialValue = addressLabels.links[key]

if (socialValue.toLowerCase().includes(searchTerm)) {
acc.push({name: key, value: socialValue })
}

return acc
}, [] as SearchLabels['links'])

if (labels.length || Object.keys(links).length) {
return {
address: addressLabels.address,
labels,
links
}
}

return null
}).filter((result): result is SearchLabels => !!result)

return results || []
}
1 change: 1 addition & 0 deletions labels/0x0035fc5208ef989c28d47e552e92b0c507d2b318.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x0035fc5208ef989c28d47e552e92b0c507d2b318",
"labels": [
{ "type": "info", "value": "Banteg" },
{ "type": "info", "value": "Builder" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x070341aa5ed571f0fb2c4a5641409b1a46b4961b.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x070341aa5ed571f0fb2c4a5641409b1a46b4961b",
"labels": [
{ "type": "info", "value": "Penn Blockchain" },
{ "type": "info", "value": "University" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x11e4857bb9993a50c685a79afad4e6f65d518dda.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x11e4857bb9993a50c685a79afad4e6f65d518dda",
"labels": [
{ "type": "info", "value": "Hayden Adams" },
{ "type": "info", "value": "Builder" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x2d407ddb06311396fe14d4b49da5f0471447d45c.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x2d407ddb06311396fe14d4b49da5f0471447d45c",
"labels": [
{ "type": "info", "value": "Andre Cronje" },
{ "type": "info", "value": "Founder" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x2ef2d6e5d34b5f3b465adfa1b38204dbd274b32a.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x2ef2d6e5d34b5f3b465adfa1b38204dbd274b32a",
"labels": [
{
"type": "info",
Expand Down
1 change: 1 addition & 0 deletions labels/0x3ddfa8ec3052539b6c9549f12cea2c295cff5296.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x3ddfa8ec3052539b6c9549f12cea2c295cff5296d",
"labels": [
{
"type": "info",
Expand Down
1 change: 1 addition & 0 deletions labels/0x42f9134e9d3bf7eee1f8a5ac2a4328b059e7468c.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x42f9134e9d3bf7eee1f8a5ac2a4328b059e7468c",
"labels": [
{ "type": "info", "value": "Kain Warwick" },
{ "type": "info", "value": "Founder" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x489a8756c18c0b8b24ec2a2b9ff3d4d447f79bec.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x489a8756c18c0b8b24ec2a2b9ff3d4d447f79bec",
"labels": [
{ "type": "danger", "value": "Binance Bridge Exploiter" },
{ "type": "danger", "value": "Hack" }
Expand Down
1 change: 1 addition & 0 deletions labels/0x50495480cce225c8476e90466d8615a9e6a5e004.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x50495480cce225c8476e90466d8615a9e6a5e004",
"labels": [
{ "type": "info", "value": "Dragonfly Capital" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x61258f12c459984f32b83c86a6cc10aa339396de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x61258f12c459984f32b83c86a6cc10aa339396de",
"labels": [
{ "type": "info", "value": "Bain Capital Ventures" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x6626593c237f530d15ae9980a95ef938ac15c35c.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x6626593c237f530d15ae9980a95ef938ac15c35c",
"labels": [
{ "type": "info", "value": "Gauntlet" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x683a4f9915d6216f73d6df50151725036bd26c02.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x683a4f9915d6216f73d6df50151725036bd26c02",
"labels": [
{ "type": "info", "value": "Gauntlet" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x7a16ff8270133f063aab6c9977183d9e72835428.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x7a16ff8270133f063aab6c9977183d9e72835428",
"labels": [
{
"type": "info",
Expand Down
1 change: 1 addition & 0 deletions labels/0x7ae109a63ff4dc852e063a673b40bed85d22e585.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x7ae109a63ff4dc852e063a673b40bed85d22e585",
"labels": [
{ "type": "info", "value": "Blockchain at Berkeley" },
{ "type": "info", "value": "University" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x8169522c2c57883e8ef80c498aab7820da539806.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x8169522c2c57883e8ef80c498aab7820da539806",
"labels": [
{ "type": "info", "value": "Geoffrey Hayes" },
{ "type": "info", "value": "Compound Delegate" }
Expand Down
1 change: 1 addition & 0 deletions labels/0x88fb3d509fc49b515bfeb04e23f53ba339563981.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x88fb3d509fc49b515bfeb04e23f53ba339563981",
"labels": [
{ "type": "info", "value": "Robert Leshner" },
{ "type": "info", "value": "Angel" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x8d07d225a769b7af3a923481e1fdf49180e6a265.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x8d07d225a769b7af3a923481e1fdf49180e6a265",
"labels": [
{ "type": "info", "value": "Monet Supply" },
{ "type": "info", "value": "Governance Participant" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x9aa835bc7b8ce13b9b0c9764a52fbf71ac62ccf1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x9aa835bc7b8ce13b9b0c9764a52fbf71ac62ccf1",
"labels": [
{ "type": "info", "value": "a16z" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x9b68c14e936104e9a7a24c712beecdc220002984.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x9b68c14e936104e9a7a24c712beecdc220002984",
"labels": [
{ "type": "info", "value": "Getty Hill" },
{ "type": "info", "value": "GFX Labs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0x9c5083dd4838e120dbeac44c052179692aa5dac5.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0x9c5083dd4838e120dbeac44c052179692aa5dac5",
"labels": [{ "type": "info", "value": "Tetranode" }],
"links": {
"twitter": "https://twitter.com/Tetranode"
Expand Down
1 change: 1 addition & 0 deletions labels/0xa1b61405791170833070c0ea61ed28728a840241.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xa1b61405791170833070c0ea61ed28728a840241",
"labels": [
{ "type": "info", "value": "Paradigm" },
{ "type": "info", "value": "VCs" },
Expand Down
1 change: 1 addition & 0 deletions labels/0xab5801a7d398351b8be11c439e05c5b3259aec9b.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xab5801a7d398351b8be11c439e05c5b3259aec9b",
"labels": [{ "type": "info", "value": "Vitalik Buterin" }],
"links": {
"twitter": "https://twitter.com/VitalikButerin"
Expand Down
1 change: 1 addition & 0 deletions labels/0xc95c558daa63b1a79331b2ab4a2a7af375384d3b.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xc95c558daa63b1a79331b2ab4a2a7af375384d3b",
"labels": [{ "type": "info", "value": "samczsun" }],
"links": {
"twitter": "https://twitter.com/samczsun",
Expand Down
1 change: 1 addition & 0 deletions labels/0xd8da6bf26964af9d7eed9e03e53415d37aa96045.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"labels": [{ "type": "info", "value": "Vitalik Buterin" }],
"links": {
"twitter": "https://twitter.com/VitalikButerin"
Expand Down
1 change: 1 addition & 0 deletions labels/0xdc1f98682f4f8a5c6d54f345f448437b83f5e432.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xdc1f98682f4f8a5c6d54f345f448437b83f5e432",
"labels": [
{ "type": "info", "value": "Blockchain at Colombia" },
{ "type": "info", "value": "University" },
Expand Down
1 change: 1 addition & 0 deletions labels/0xe74b28c2eae8679e3ccc3a94d5d0de83ccb84705.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xe74b28c2eae8679e3ccc3a94d5d0de83ccb84705",
"labels": [
{
"type": "danger",
Expand Down
1 change: 1 addition & 0 deletions labels/0xea6c3db2e7fca00ea9d7211a03e83f568fc13bf7.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"address": "0xea6c3db2e7fca00ea9d7211a03e83f568fc13bf7",
"labels": [
{ "type": "info", "value": "Polychain Capital" },
{ "type": "info", "value": "VCs" },
Expand Down
5 changes: 5 additions & 0 deletions schemas/label.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"title": "LlamaFolio Label Schema",
"required": ["labels", "links"],
"properties": {
"address:": {
"type": "string",
"default": " ",
"example": "0x0000000000000000000000000000000000000000"
},
"labels": {
"type": "array",
"default": [],
Expand Down