Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

feat: switch to ANS-104 #11

Open
wants to merge 4 commits into
base: master
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
4 changes: 2 additions & 2 deletions common/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"types": "dist/index",
"dependencies": {
"@kyve/contract-lib": "0.1.0-alpha.14",
"ans104": "joshbenaron/ans104",
"ardb": "^1.0.8",
"arweave": "^1.10.11",
"arweave-bundles": "^1.0.3",
"arweave": "^1.10.15",
"chalk": "^4.1.1",
"fecha": "^4.2.1",
"object-hash": "^2.2.0",
Expand Down
8 changes: 0 additions & 8 deletions common/core/src/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import deepHash from "arweave/node/lib/deepHash";
import Arweave from "arweave";
import ArweaveBundles from "arweave-bundles";

export const arweaveClient = new Arweave({
host: "arweave.net",
port: 443,
protocol: "https",
});

export const arweaveBundles = ArweaveBundles({
utils: Arweave.utils,
crypto: Arweave.crypto,
deepHash,
});
37 changes: 14 additions & 23 deletions common/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
import { JWKInterface } from "arweave/node/lib/wallet";
import hash from "object-hash";
import { Observable } from "rxjs";
import { arweaveBundles as bundles, arweaveClient } from "./extensions";
import { arweaveClient } from "./extensions";
import { DataItemCreateOptions } from "ans104/lib/ar-data-base";
import { bundleAndSignData } from "ans104";

import { Pool, Governance } from "@kyve/contract-lib";
import { GQLEdgeTransactionInterface } from "ardb/lib/faces/gql";
import { deposit, untilMined } from "./helper";

import Log from "./logger";
import { create } from "arweave-bundles";

export const APP_NAME = "KYVE - DEV";

Expand Down Expand Up @@ -239,31 +240,21 @@ export default class KYVE {
const buffer = this.uploaderBuffer;
this.uploaderBuffer = [];

const items = [];
const items: DataItemCreateOptions[] = [];
for (const entry of buffer) {
const item = await bundles.createData(
{
data: JSON.stringify(entry.data),
tags: [
{ name: "Application", value: APP_NAME },
{ name: "Pool", value: this.poolID.toString() },
...(entry.tags || []),
],
},
this.keyfile
);
items.push(await bundles.sign(item, this.keyfile));
items.push({
data: JSON.stringify(entry.data),
tags: [
{ name: "Application", value: APP_NAME },
{ name: "Pool", value: this.poolID.toString() },
...(entry.tags || []),
],
});
}

const bundle = await bundles.bundleData(items);
const transaction = await this.arweave.createTransaction(
{ data: JSON.stringify(bundle) },
this.keyfile
);
const bundle = await bundleAndSignData(items, this.keyfile);
const transaction = await bundle.toTransaction(this.arweave);

transaction.addTag("Bundle-Format", "json");
transaction.addTag("Bundle-Version", "1.0.0");
transaction.addTag("Content-Type", "application/json");
transaction.addTag("App-Name", "SmartWeaveAction");
transaction.addTag("App-Version", "0.3.0");
transaction.addTag("Contract", this.pool.id!);
Expand Down
1 change: 1 addition & 0 deletions contract/pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"esbuild": "^0.11.2"
},
"dependencies": {
"ans104": "joshbenaron/ans104",
"arweave-bundles": "^1.0.3",
"prando": "^6.0.1"
}
Expand Down
20 changes: 18 additions & 2 deletions contract/pool/src/modules/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionInterface, StateInterface } from "../faces";
import { DataItemJson } from "arweave-bundles";
import { unbundleData } from "ans104";

declare const ContractAssert: any;
declare const SmartWeave: any;
Expand All @@ -17,7 +18,7 @@ export const Register = async (
"Only the uploader can register data."
);

const ids: string[] = [];
let ids: string[] = [];
const tags = await GetTags(SmartWeave.transaction.id);

if (
Expand All @@ -28,7 +29,7 @@ export const Register = async (
(tag) => tag.name === "Bundle-Version" && tag.value === "1.0.0"
) > -1
) {
// Transaction is a bundle
// Transaction is an ANS-102 bundle
const data = JSON.parse(
await SmartWeave.unsafeClient.transactions.getData(
SmartWeave.transaction.id,
Expand All @@ -38,6 +39,21 @@ export const Register = async (

const items = data.items as DataItemJson[];
items.forEach((item) => ids.push(item.id));
} else if (
tags.findIndex(
(tag) => tag.name === "Bundle-Format" && tag.value === "binary"
) > -1 &&
tags.findIndex(
(tag) => tag.name === "Bundle-Version" && tag.value === "2.0.0"
) > -1
) {
// Transaction is an ANS-104 bundle
const data = await SmartWeave.unsafeClient.transactions.getData(
SmartWeave.transaction.id
);

const bundle = unbundleData(data);
ids = bundle.getIds();
} else {
// Transaction is not a bundle
ids.push(SmartWeave.transaction.id);
Expand Down
2 changes: 2 additions & 0 deletions integrations/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare global {
}
}

// @ts-ignore
global.__rootdir__ = __dirname || process.cwd();

if (process.env.SEND_STATISTICS) {
Expand All @@ -34,6 +35,7 @@ if (process.env.SEND_STATISTICS) {
release: "node@" + process.env.npm_package_version,
integrations: [
new RewriteFrames({
// @ts-ignore
root: global.__rootdir__,
}),
],
Expand Down
Loading