Skip to content

Commit

Permalink
Merge pull request #75 from moreal/remove-non-rdb-mode
Browse files Browse the repository at this point in the history
🧹 PDX-248: Clean up codes related to non-rdb mode
  • Loading branch information
moreal authored Dec 18, 2023
2 parents bbf0314 + 85b57b8 commit dcd7cb8
Show file tree
Hide file tree
Showing 40 changed files with 94 additions and 1,688 deletions.
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
NC_REGISTRY_ENDPOINT=
NC_UPSTREAM_PLANET=
NC_DOWNSTREAM_PLANET=
MONITOR_STATE_STORE_PATH=
NC_VAULT_ADDRESS=
NC_VAULT_AVATAR_ADDRESS=
NC_UPSTREAM_PRIVATE_KEY=
Expand Down
21 changes: 21 additions & 0 deletions src/actions/burn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Address } from "@planetarium/account";
import { RecordView } from "@planetarium/bencodex";
import { FungibleAssetValue, encodeCurrency } from "@planetarium/tx";

export function encodeBurnAssetAction(
sender: Address,
amount: FungibleAssetValue,
memo: string,
): RecordView {
return new RecordView(
{
type_id: "burn_asset",
values: [
sender.toBytes(),
[encodeCurrency(amount.currency), amount.rawValue],
memo,
],
},
"text",
);
}
38 changes: 10 additions & 28 deletions src/minter.ts → src/actions/mint.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
import { Address } from "@planetarium/account";
import { RecordView, Value } from "@planetarium/bencodex";
import { encodeCurrency } from "@planetarium/tx";
import {
IFungibleAssetValues,
IFungibleItems,
IMinter,
} from "./interfaces/minter";
import { Signer } from "./signer";
import { FungibleAssetValue, encodeCurrency } from "@planetarium/tx";
import { FungibleItemId } from "../types/fungible-item-id";

export class Minter implements IMinter {
private readonly signer: Signer;

constructor(signer: Signer) {
this.signer = signer;
}

async mintAssets(
assets: [IFungibleAssetValues | IFungibleItems],
memo: string | null,
): Promise<string> {
const action = encodeMintAssetsAction(assets, memo);
return await this.signer.sendTx(action);
}

getMinterAddress(): Promise<Address> {
return this.signer.getAddress();
}
export interface IFungibleAssetValues {
recipient: string;
amount: FungibleAssetValue;
}

getMinterPlanet(): string {
return this.signer.getSignPlanet();
}
export interface IFungibleItems {
recipient: string;
fungibleItemId: FungibleItemId;
count: number;
}

function encodeMintSpec(value: IFungibleAssetValues | IFungibleItems): Value {
Expand Down
24 changes: 24 additions & 0 deletions src/actions/transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Address } from "@planetarium/account";
import { RecordView } from "@planetarium/bencodex";
import { FungibleAssetValue, encodeCurrency } from "@planetarium/tx";

export function encodeTransferAssetAction(
recipient: Address,
sender: Address,
amount: FungibleAssetValue,
memo: string,
) {
return new RecordView(
{
type_id: "transfer_asset5",
values: {
// `encodeFungibleAssetValue()` wasn't exported properly.
amount: [encodeCurrency(amount.currency), amount.rawValue],
...(memo === null ? {} : { memo }),
recipient: Buffer.from(recipient.toBytes()),
sender: Buffer.from(sender.toBytes()),
},
},
"text",
);
}
42 changes: 0 additions & 42 deletions src/asset-burner.ts

This file was deleted.

58 changes: 0 additions & 58 deletions src/asset-transfer.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import { Address } from "@planetarium/account";
import { IHeadlessGraphQLClient } from "../interfaces/headless-graphql-client";
import { IMonitorStateHandler } from "../interfaces/monitor-state-handler";
import { IHeadlessGraphQLClient } from "../headless-graphql-client";
import { AssetTransferredEvent } from "../types/asset-transferred-event";
import { TransactionLocation } from "../types/transaction-location";
import { NineChroniclesMonitor } from "./ninechronicles-block-monitor";

export class AssetsTransferredMonitor extends NineChroniclesMonitor<AssetTransferredEvent> {
private readonly _address: Address;

constructor(
monitorStateHandler: IMonitorStateHandler,
headlessGraphQLClient: IHeadlessGraphQLClient,
address: Address,
) {
super(monitorStateHandler, headlessGraphQLClient);
this._address = address;
}

protected async getEvents(
blockIndex: number,
): Promise<(AssetTransferredEvent & TransactionLocation)[]> {
return getAssetTransferredEvents(
this._headlessGraphQLClient,
this._address,
blockIndex,
);
}
}

export async function getAssetTransferredEvents(
headlessGraphQLClient: IHeadlessGraphQLClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Address } from "@planetarium/account";
import { IHeadlessGraphQLClient } from "../interfaces/headless-graphql-client";
import { IMonitorStateHandler } from "../interfaces/monitor-state-handler";
import { IHeadlessGraphQLClient } from "../headless-graphql-client";
import { GarageUnloadEvent } from "../types/garage-unload-event";
import { TransactionLocation } from "../types/transaction-location";
import { NineChroniclesMonitor } from "./ninechronicles-block-monitor";

export type ValidatedGarageUnloadEvent = Omit<GarageUnloadEvent, "memo"> & {
parsedMemo: {
Expand All @@ -13,33 +10,6 @@ export type ValidatedGarageUnloadEvent = Omit<GarageUnloadEvent, "memo"> & {
};
};

export class GarageUnloadMonitor extends NineChroniclesMonitor<ValidatedGarageUnloadEvent> {
private readonly _agentAddress: Address;
private readonly _avatarAddress: Address;

constructor(
monitorStateHandler: IMonitorStateHandler,
headlessGraphQLClient: IHeadlessGraphQLClient,
agentAddress: Address,
avatarAddress: Address,
) {
super(monitorStateHandler, headlessGraphQLClient);
this._agentAddress = agentAddress;
this._avatarAddress = avatarAddress;
}

protected async getEvents(
blockIndex: number,
): Promise<(ValidatedGarageUnloadEvent & TransactionLocation)[]> {
return getGarageUnloadEvents(
this._headlessGraphQLClient,
this._agentAddress,
this._avatarAddress,
blockIndex,
);
}
}

export async function getGarageUnloadEvents(
headlessGraphQLClient: IHeadlessGraphQLClient,
agentAddress: Address,
Expand Down
95 changes: 0 additions & 95 deletions src/headless-graphql-client.spec.ts

This file was deleted.

Loading

0 comments on commit dcd7cb8

Please sign in to comment.