Skip to content

Commit

Permalink
Merge pull request #36 from OPENSPHERE-Inc/next
Browse files Browse the repository at this point in the history
Metal on Symbol V2 update
  • Loading branch information
hanatyan128 authored Feb 29, 2024
2 parents 3b69ede + 92d407d commit 3529243
Show file tree
Hide file tree
Showing 55 changed files with 3,952 additions and 464 deletions.
547 changes: 448 additions & 99 deletions README.md

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metal-on-symbol",
"version": "0.2.7",
"version": "0.3.1-rc.10",
"description": "Metal on Symbol PoC",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -21,6 +21,7 @@
"devDependencies": {
"@types/jest": "^29.2.3",
"@types/long": "^5.0.0",
"@types/mime": "^3.0.4",
"@types/prompts": "^2.4.2",
"@types/uuid": "^8.3.4",
"cross-env": "^7.0.3",
Expand All @@ -30,15 +31,17 @@
"typescript": "^4.9.3"
},
"dependencies": {
"@opensphere-inc/symbol-service": "^1.2.10",
"@opensphere-inc/symbol-service": "^1.3.1",
"bs58": "^5.0.0",
"catbuffer-typescript": "^1.0.2",
"dotenv": "^16.0.3",
"js-base64": "^3.7.3",
"js-sha3": "https://github.com/Propine/js-sha3.git",
"long": "^5.2.1",
"mime": "^3.0.0",
"moment": "^2.29.4",
"prompts": "^2.4.2",
"rxjs": "^7.5.7",
"symbol-openapi-typescript-fetch-client": "^1.0.3",
"symbol-sdk": "^2.0.4",
"uuid": "^9.0.0"
},
Expand Down Expand Up @@ -73,7 +76,10 @@
"encrypt": "node dist/cli/main.js encrypt",
"decrypt": "node dist/cli/main.js decrypt",
"build-pack": "yarn build && yarn pack",
"build-publish": "yarn build && yarn publish"
"build-publish": "yarn build && yarn publish",
"scrap-v1": "node dist/cli/main.js scrap-v1",
"reinforce-v1": "node dist/cli/main.js reinforce-v1",
"cli-help": "node dist/cli/main.js --help"
},
"bin": {
"metal": "./dist/cli/main.js"
Expand Down
51 changes: 32 additions & 19 deletions src/cli/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {MetalService, SymbolService} from "../services";
import Long from "long";
import moment from "moment";
import prompts from "prompts";
import {
Account,
Address,
Expand All @@ -9,16 +11,19 @@ import {
PublicAccount,
UInt64
} from "symbol-sdk";
import {Logger} from "../libs";
import Long from "long";
import moment from "moment";
import prompts from "prompts";
import {AggregateUndeadTransaction, NecromancyService, SignedAggregateTx} from "@opensphere-inc/symbol-service";
import { Logger } from "../libs";
import {
AggregateUndeadTransaction,
MetalServiceV2,
NecromancyService,
SignedAggregateTx,
SymbolService
} from "../services";


export const isValueOption = (token?: string) => !token?.startsWith("-");
export let symbolService: SymbolService;
export let metalService: MetalService;
export let metalService: MetalServiceV2;
export let necromancyService: NecromancyService;
export const deadlineMinHours = 5;
export const deadlineMarginHours = 1;
Expand All @@ -41,7 +46,7 @@ export const initCliEnv = async <T extends NodeInput>(input: Readonly<T>, feeRat
const { networkType } = await symbolService.getNetwork();
Logger.debug(`Using Node URL: ${input.nodeUrl} (network_type:${networkType})`);

metalService = new MetalService(symbolService);
metalService = new MetalServiceV2(symbolService);
necromancyService = new NecromancyService(symbolService, {
deadlineUnitHours: symbolService.config.deadline_hours,
deadlineMarginHours: deadlineMarginHours,
Expand Down Expand Up @@ -99,7 +104,8 @@ export const announceBatches = async (
stdout: process.stderr,
})).decision;
if (!decision) {
throw new Error("Canceled by user.");
Logger.warn("Canceled by user.");
return false;
}
}

Expand All @@ -114,12 +120,15 @@ export const announceBatches = async (
} else {
Logger.info(`Completed in ${moment().diff(startAt, "seconds", true)} secs.`);
}

return true;
};

interface ExecuteBatchesResult {
totalFee: UInt64,
batches?: SignedAggregateTx[],
undeadBatches?: AggregateUndeadTransaction[],
totalFee: UInt64;
batches?: SignedAggregateTx[];
undeadBatches?: AggregateUndeadTransaction[];
announced: boolean;
}

export const buildAndExecuteBatches = async (
Expand Down Expand Up @@ -149,22 +158,24 @@ export const buildAndExecuteBatches = async (
UInt64.fromUint(0)
);

let announced = false;
if (canAnnounce) {
Logger.info(
`Announcing ${batches.length} aggregate TXs ` +
`with fee ${SymbolService.toXYM(Long.fromString(totalFee.toString()))} XYM total.`
);
await announceBatches(
batches,
signerAccount,
maxParallels,
showPrompt
);
announced = await announceBatches(
batches,
signerAccount,
maxParallels,
showPrompt
);
}

return {
batches,
totalFee,
announced,
};
};

Expand Down Expand Up @@ -197,12 +208,13 @@ export const buildAndExecuteUndeadBatches = async (
UInt64.fromUint(0)
);

let announced = false;
if (canAnnounce) {
Logger.info(
`Announcing ${undeadBatches.length} aggregate TXs ` +
`with fee ${SymbolService.toXYM(Long.fromString(totalFee.toString()))} XYM total.`
);
await announceBatches(
announced = await announceBatches(
await necromancyService.pickAndCastTxBatches(undeadBatches),
signerAccount,
maxParallels,
Expand All @@ -213,6 +225,7 @@ export const buildAndExecuteUndeadBatches = async (
return {
undeadBatches,
totalFee,
announced,
};
};

Expand Down
Loading

0 comments on commit 3529243

Please sign in to comment.