Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
rename FilecoinApi's blockchain member to be consistent with ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeseese committed Jan 19, 2021
1 parent 140c544 commit d9defdd
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/chains/filecoin/filecoin/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ import {
import Emittery from "emittery";
import { HeadChange, HeadChangeType } from "./things/head-change";

const _blockchain = Symbol("blockchain");

export default class FilecoinApi implements types.Api {
readonly [index: string]: (...args: any) => Promise<any>;

readonly #getId = (id => () => Quantity.from(++id))(0);
readonly #subscriptions = new Map<string, Emittery.UnsubscribeFn>();
private readonly [_blockchain]: Blockchain;
readonly #blockchain: Blockchain;

constructor(blockchain: Blockchain) {
this[_blockchain] = blockchain;
this.#blockchain = blockchain;
}

async stop(): Promise<void> {
return await this[_blockchain].stop();
return await this.#blockchain.stop();
}

async "Filecoin.ChainGetGenesis"(): Promise<SerializedTipset> {
return this[_blockchain].latestTipset().serialize();
return this.#blockchain.latestTipset().serialize();
}

async "Filecoin.ChainHead"(): Promise<SerializedTipset> {
return this[_blockchain].latestTipset().serialize();
return this.#blockchain.latestTipset().serialize();
}

"Filecoin.ChainNotify"(): PromiEvent<Quantity> {
Expand All @@ -52,10 +50,10 @@ export default class FilecoinApi implements types.Api {

const currentHead = new HeadChange({
type: HeadChangeType.HCCurrent,
val: this[_blockchain].latestTipset()
val: this.#blockchain.latestTipset()
});

this[_blockchain].on("tipset", (tipset: Tipset) => {
this.#blockchain.on("tipset", (tipset: Tipset) => {
const newHead = new HeadChange({
type: HeadChangeType.HCApply,
val: tipset
Expand All @@ -76,19 +74,19 @@ export default class FilecoinApi implements types.Api {
}

async "Filecoin.StateListMiners"(): Promise<Array<SerializedMiner>> {
return [this[_blockchain].miner.serialize()];
return [this.#blockchain.miner.serialize()];
}

async "Filecoin.WalletDefaultAddress"(): Promise<SerializedAddress> {
return this[_blockchain].address.serialize();
return this.#blockchain.address.serialize();
}

async "Filecoin.WalletBalance"(address: string): Promise<string> {
let managedAddress = this[_blockchain].address;
let managedAddress = this.#blockchain.address;

// For now, anything but our default address will have no balance
if (managedAddress.value == address) {
return this[_blockchain].balance.serialize();
return this.#blockchain.balance.serialize();
} else {
return "0";
}
Expand All @@ -98,19 +96,19 @@ export default class FilecoinApi implements types.Api {
serializedProposal: SerializedStorageProposal
): Promise<SerializedRootCID> {
let proposal = new StorageProposal(serializedProposal);
let proposalRootCid = await this[_blockchain].startDeal(proposal);
let proposalRootCid = await this.#blockchain.startDeal(proposal);

return proposalRootCid.serialize();
}

async "Filecoin.ClientListDeals"(): Promise<Array<SerializedDeal>> {
return this[_blockchain].deals.map(deal => deal.serialize());
return this.#blockchain.deals.map(deal => deal.serialize());
}

async "Filecoin.ClientFindData"(
rootCid: SerializedRootCID
): Promise<Array<SerializedRetrievalOffer>> {
let remoteOffer = await this[_blockchain].createRetrievalOffer(
let remoteOffer = await this.#blockchain.createRetrievalOffer(
new RootCID(rootCid)
);
return [remoteOffer.serialize()];
Expand All @@ -119,13 +117,13 @@ export default class FilecoinApi implements types.Api {
async "Filecoin.ClientHasLocal"(
rootCid: SerializedRootCID
): Promise<boolean> {
return await this[_blockchain].hasLocal(rootCid["/"]);
return await this.#blockchain.hasLocal(rootCid["/"]);
}

async "Filecoin.ClientRetrieve"(
retrievalOffer: SerializedRetrievalOffer
): Promise<object> {
await this[_blockchain].retrieve(new RetrievalOffer(retrievalOffer));
await this.#blockchain.retrieve(new RetrievalOffer(retrievalOffer));

// Return value is a placeholder.
//
Expand All @@ -137,7 +135,7 @@ export default class FilecoinApi implements types.Api {
}

async "Filecoin.GanacheMineTipset"(): Promise<SerializedTipset> {
await this[_blockchain].mineTipset();
return this[_blockchain].latestTipset().serialize();
await this.#blockchain.mineTipset();
return this.#blockchain.latestTipset().serialize();
}
}

0 comments on commit d9defdd

Please sign in to comment.