Skip to content

Commit

Permalink
Merge pull request #82 from golemfactory/b0.2_clean
Browse files Browse the repository at this point in the history
B0.2 clean
  • Loading branch information
mdtanrikulu committed Dec 8, 2020
2 parents fcf099d + 8a9e1a9 commit ba77291
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 286 deletions.
8 changes: 3 additions & 5 deletions examples/blender/blender.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { program } = require("commander");

dayjs.extend(duration);

const { asyncWith, range } = utils;
const { asyncWith, logUtils, range } = utils;

async function main(subnetTag) {
const _package = await vm.repo(
Expand Down Expand Up @@ -69,9 +69,7 @@ async function main(subnetTag) {
"10.0",
undefined,
subnetTag,
(event) => {
console.debug(event);
}
logUtils.logSummary()
),
async (engine) => {
for await (let task of engine.map(
Expand All @@ -86,7 +84,7 @@ async function main(subnetTag) {
}

program
.option('--subnet-tag <subnet>', 'set subnet name', 'devnet-alpha.3')
.option('--subnet-tag <subnet>', 'set subnet name', 'community.3')
.option('-d, --debug', 'output extra debugging');
program.parse(process.argv);
if (program.debug) {
Expand Down
7 changes: 3 additions & 4 deletions examples/blender/blender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import path from "path";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { Engine, Task, utils, vm, WorkContext } from "yajsapi";
import { logSummary } from "yajsapi/utils/log";
import { program } from "commander";

dayjs.extend(duration);

const { asyncWith, range } = utils;
const { asyncWith, logUtils, range } = utils;

async function main(subnetTag: string) {
const _package = await vm.repo(
Expand Down Expand Up @@ -71,7 +70,7 @@ async function main(subnetTag: string) {
"10.0",
undefined,
subnetTag,
logSummary()
logUtils.logSummary()
),
async (engine: Engine): Promise<void> => {
for await (let task of engine.map(
Expand All @@ -86,7 +85,7 @@ async function main(subnetTag: string) {
}

program
.option('--subnet-tag <subnet>', 'set subnet name', 'devnet-alpha.3')
.option('--subnet-tag <subnet>', 'set subnet name', 'community.3')
.option('-d, --debug', 'output extra debugging');
program.parse(process.argv);
if (program.debug) {
Expand Down
2 changes: 1 addition & 1 deletion examples/low-level-api/listOffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const promiseTimeout = (seconds) =>
}, seconds * 1000)
);

program.option('--subnet-tag <subnet>', 'set subnet name', 'devnet-alpha.3');
program.option('--subnet-tag <subnet>', 'set subnet name', 'community.3');
program.parse(process.argv);
console.log(`Using subnet: ${program.subnetTag}`);

Expand Down
2 changes: 1 addition & 1 deletion examples/low-level-api/listOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const promiseTimeout = (seconds: number) =>
}, seconds * 1000)
);

program.option('--subnet-tag <subnet>', 'set subnet name', 'devnet-alpha.3');
program.option('--subnet-tag <subnet>', 'set subnet name', 'community.3');
program.parse(process.argv);
console.log(`Using subnet: ${program.subnetTag}`);

Expand Down
5 changes: 3 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"js:blender": "node ./blender/blender.js",
"ts:blender": "ts-node-script ./blender/blender.ts",
"js:low": "node ./low-level-api/listOffers.js",
"ts:low": "ts-node-script ./low-level-api/listOffers.ts"
"ts:low": "ts-node-script ./low-level-api/listOffers.ts",
"clean": "rimraf node_modules/ yarn.lock || echo 'Project is already clean'"
},
"author": "Muhammed Tanrikulu <muhammed@golem.network>",
"license": "LGPL-3.0",
"dependencies": {
"bluebird": "^3.5.0",
"dayjs": "^1.8.31",
"ts-node": "^9.0.0",
"yajsapi": "file:../"
"yajsapi": "^0.2.0"
},
"devDependencies": {
"tsconfig-paths": "^3.9.0",
Expand Down
81 changes: 41 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
{
"name": "yajsapi",
"version": "0.2.0-alpha.0",
"description": "NodeJS API for Next Golem",
"repository": "https://github.com/golemfactory/yajsapi",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "rm -Rf node_modules/ dist/",
"build": "tsc",
"test": "npm run build && node dist/index.js"
},
"author": "Muhammed Tanrikulu <muhammed@golem.network>",
"license": "LGPL-3.0",
"dependencies": {
"@rauschma/stringio": "^1.4.0",
"@types/bluebird": "^3.5.33",
"axios": "^0.19.2",
"bluebird": "^3.5.0",
"commander": "^6.2.0",
"dayjs": "~1.9.1",
"js-csp": "^1.0.1",
"eccrypto": "^1.1.5",
"minimist": "^1.2.5",
"rewire": "^3.0.2",
"secp256k1": "^4.0.2",
"sgx-ias-js": "~0.1.1",
"tmp": "^0.2.1",
"utf8": "~3.0.0",
"uuid": "^8.3.1",
"winston": "^3.3.3",
"ya-ts-client": "^0.2.0"
},
"devDependencies": {
"@types/eccrypto": "^1.1.2",
"@types/node": "14.6.2",
"@types/utf8": "^2.1.6",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.7"
}
"name": "yajsapi",
"version": "0.2.0",
"description": "NodeJS API for Next Golem",
"repository": "https://github.com/golemfactory/yajsapi",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "rimraf node_modules/ dist/ || echo 'Project is already clean'",
"build": "tsc",
"test": "npm run build && node dist/index.js"
},
"author": "Muhammed Tanrikulu <muhammed@golem.network>",
"license": "LGPL-3.0",
"dependencies": {
"@rauschma/stringio": "^1.4.0",
"@types/bluebird": "^3.5.33",
"axios": "^0.19.2",
"bluebird": "^3.5.0",
"commander": "^6.2.0",
"dayjs": "~1.9.1",
"eccrypto": "^1.1.5",
"js-csp": "^1.0.1",
"minimist": "^1.2.5",
"rewire": "^3.0.2",
"secp256k1": "^4.0.2",
"sgx-ias-js": "~0.1.1",
"tmp": "^0.2.1",
"utf8": "~3.0.0",
"uuid": "^8.3.1",
"winston": "^3.3.3",
"ya-ts-client": "^0.2.0"
},
"devDependencies": {
"@types/eccrypto": "^1.1.2",
"@types/node": "14.6.2",
"@types/utf8": "^2.1.6",
"rimraf": "^3.0.2",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.9.7"
}
}
6 changes: 4 additions & 2 deletions yajsapi/props/inf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export enum RuntimeType {
WASMTIME = "wasmtime",
EMSCRIPTEN = "emscripten",
VM = "vm",
SGX_WASI = "sgx",
SGX_JS_SP = "sgx-js-sp",
SGX = "sgx",
SGX_JS = "sgx-js",
SGX_WASM = "sgx-wasm",
SGX_WASI = "sgx-wasi",
}

export class InfBase {
Expand Down
7 changes: 6 additions & 1 deletion yajsapi/rest/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ class Activity {
}
} catch (error) {
logger.error(`Failed to destroy activity: ${this._id}`);
} finally {
try {
await this._api.destroyActivity(this._id);
} catch (error) {
//suppress api error
}
}
await this._api.destroyActivity(this._id);
}
}

Expand Down
5 changes: 3 additions & 2 deletions yajsapi/rest/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export class Agreement {
return new AgreementDetails(data);
}

async confirm() {
async confirm(): Promise<boolean> {
await this._api.confirmAgreement(this._id);
await this._api.waitForApproval(this._id, 90, 100);
let { data: msg } = await this._api.waitForApproval(this._id, 90, 100);
return msg.trim().toLowerCase() == "approved";
}
}

Expand Down
6 changes: 4 additions & 2 deletions yajsapi/rest/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export class Invoice extends yInvoice {
}

async accept(amount: number | string, allocation: Allocation) {
let acceptance: yap.Acceptance;
let acceptance: yap.Acceptance = {
totalAmountAccepted: amount.toString(),
allocationId: allocation.id
};
acceptance!.totalAmountAccepted = amount.toString();
acceptance!.allocationId = allocation.id;
await this._api.acceptInvoice(this.invoiceId, acceptance!);
Expand Down Expand Up @@ -264,7 +267,6 @@ export class Payment {
yield invoice;
}
}
if (items.length > 0) break;
}
return;
}
Expand Down
27 changes: 25 additions & 2 deletions yajsapi/runner/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class ComputationFailed extends YaEvent {
reason?: string;
}

export class PaymentsFinished extends YaEvent {}

export class SubscriptionCreated extends YaEvent {
sub_id?: string;
constructor({ sub_id }) {
Expand Down Expand Up @@ -98,8 +100,8 @@ export class NoProposalsConfirmed extends YaEvent {

constructor({ num_offers, timeout }) {
super();
if (num_offers) this.num_offers = num_offers;
if (timeout) this.timeout = timeout;
this.num_offers = num_offers;
this.timeout = timeout;
}
}

Expand Down Expand Up @@ -141,6 +143,14 @@ export class PaymentAccepted extends AgreementEvent {
}
}

export class PaymentFailed extends AgreementEvent {
// TODO add exc_info
constructor({ agr_id }) {
super();
if (agr_id) this.agr_id = agr_id;
}
}

export class PaymentPrepared extends AgreementEvent {
constructor({ agr_id }) {
super();
Expand All @@ -155,6 +165,9 @@ export class PaymentQueued extends AgreementEvent {
}
}

export class CheckingPayments extends AgreementEvent {
}

export class InvoiceReceived extends AgreementEvent {
inv_id?: string;
amount?: string;
Expand Down Expand Up @@ -277,10 +290,20 @@ export class ScriptFinished extends ScriptEvent {

export class TaskAccepted extends TaskEvent {
result?: any;
constructor({ task_id, result }) {
super();
if (task_id) this.task_id = task_id;
if (result) this.result = result;
}
}

export class TaskRejected extends TaskEvent {
reason?: string | null;
constructor({ task_id, reason }) {
super();
if (task_id) this.task_id = task_id;
if (reason) this.reason = reason;
}
}

export class DownloadStarted extends YaEvent {
Expand Down
Loading

0 comments on commit ba77291

Please sign in to comment.