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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Faust committed May 17, 2020
1 parent 103111f commit 17183fa
Show file tree
Hide file tree
Showing 21 changed files with 274 additions and 76 deletions.
75 changes: 75 additions & 0 deletions packages/platform-sdk-ark/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,73 @@ export const manifest = {
crypto: {
slip44: 111,
},
hosts: [
"https://explorer.ark.io",
"http://5.196.105.32:4003",
"http://5.196.105.33:4003",
"http://5.196.105.34:4003",
"http://5.196.105.35:4003",
"http://5.196.105.36:4003",
"http://5.196.105.37:4003",
"http://5.196.105.38:4003",
"http://5.196.105.39:4003",
"http://178.32.65.136:4003",
"http://178.32.65.137:4003",
"http://178.32.65.138:4003",
"http://178.32.65.139:4003",
"http://178.32.65.140:4003",
"http://178.32.65.141:4003",
"http://178.32.65.142:4003",
"http://178.32.65.143:4003",
"http://5.196.105.40:4003",
"http://5.196.105.41:4003",
"http://5.196.105.42:4003",
"http://5.196.105.43:4003",
"http://5.196.105.44:4003",
"http://5.196.105.45:4003",
"http://5.196.105.46:4003",
"http://5.196.105.47:4003",
"http://54.38.120.32:4003",
"http://54.38.120.33:4003",
"http://54.38.120.34:4003",
"http://54.38.120.35:4003",
"http://54.38.120.36:4003",
"http://54.38.120.37:4003",
"http://54.38.120.38:4003",
"http://54.38.120.39:4003",
"http://151.80.125.32:4003",
"http://151.80.125.33:4003",
"http://151.80.125.34:4003",
"http://151.80.125.35:4003",
"http://151.80.125.36:4003",
"http://151.80.125.37:4003",
"http://151.80.125.38:4003",
"http://151.80.125.39:4003",
"http://213.32.41.104:4003",
"http://213.32.41.105:4003",
"http://213.32.41.106:4003",
"http://213.32.41.107:4003",
"http://213.32.41.108:4003",
"http://213.32.41.109:4003",
"http://213.32.41.110:4003",
"http://213.32.41.111:4003",
"http://5.135.22.92:4003",
"http://5.135.22.93:4003",
"http://5.135.22.94:4003",
"http://5.135.22.95:4003",
"http://5.135.52.96:4003",
"http://5.135.52.97:4003",
"http://5.135.52.98:4003",
"http://5.135.52.99:4003",
"http://51.255.105.52:4003",
"http://51.255.105.53:4003",
"http://51.255.105.54:4003",
"http://51.255.105.55:4003",
"http://46.105.160.104:4003",
"http://46.105.160.105:4003",
"http://46.105.160.106:4003",
"http://46.105.160.107:4003",
],
},
devnet: {
explorer: "https://dexplorer.ark.io/",
Expand All @@ -20,6 +87,14 @@ export const manifest = {
crypto: {
slip44: 111,
},
hosts: [
"https://dexplorer.ark.io",
"http://167.114.29.51:4003",
"http://167.114.29.52:4003",
"http://167.114.29.53:4003",
"http://167.114.29.54:4003",
"http://167.114.29.55:4003",
],
},
},
abilities: {
Expand Down
25 changes: 15 additions & 10 deletions packages/platform-sdk-ark/src/services/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import isUrl from "is-url-superb";
import ky from "ky-universal";
import orderBy from "lodash.orderby";
import semver from "semver";
import { manifest } from "../manifest";

export class PeerService implements Contracts.PeerService {
private constructor(private readonly seeds: Contracts.Peer[]) {}
readonly #seeds: string[];

private constructor(seeds: string[]) {
this.#seeds = seeds;
}

public static async construct(config: Coins.Config): Promise<PeerService> {
let { network, peer, defaultPort } = config.all();
Expand All @@ -14,7 +19,7 @@ export class PeerService implements Contracts.PeerService {
defaultPort = 4003;
}

const seeds: Contracts.Peer[] = [];
let seeds: string[] = [];

try {
if (peer && isUrl(peer)) {
Expand All @@ -33,19 +38,19 @@ export class PeerService implements Contracts.PeerService {
}
}

seeds.push({ ip: seed.ip, port });
seeds.push(`http://${seed.ip}:${port}`);
}
} else {
const body: any = await ky
.get(`https://raw.githubusercontent.com/ArkEcosystem/peers/master/${network}.json`)
.json();

for (const seed of body) {
seeds.push({ ip: seed.ip, port: defaultPort });
seeds.push(`http://${seed.ip}:${defaultPort}`);
}
}
} catch (error) {
throw new Error("Failed to discovery any peers.");
} catch {
seeds = manifest.networks[config.get<string>('network')].hosts;
}

if (!seeds.length) {
Expand All @@ -59,8 +64,8 @@ export class PeerService implements Contracts.PeerService {
//
}

public getSeeds(): Contracts.Peer[] {
return this.seeds;
public getSeeds(): string[] {
return this.#seeds;
}

public async search(options: Contracts.KeyValuePair = {}): Promise<Contracts.PeerResponse[]> {
Expand All @@ -72,9 +77,9 @@ export class PeerService implements Contracts.PeerService {
options.timeout = 3000;
}

const seed: Contracts.Peer = this.seeds[Math.floor(Math.random() * this.seeds.length)];
const seed: string = this.#seeds[Math.floor(Math.random() * this.#seeds.length)];

const body: any = await ky(`http://${seed.ip}:${seed.port}/api/peers`, {
const body: any = await ky(`${seed}/api/peers`, {
...options,
...{
headers: {
Expand Down
8 changes: 4 additions & 4 deletions packages/platform-sdk-atom/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const manifest = {
symbol: "ATOM",
},
crypto: {
chainId: "cosmoshub-3",
networkId: "cosmoshub-3",
slip44: 118,
bech32: "cosmos",
},
Expand All @@ -20,7 +20,7 @@ export const manifest = {
symbol: "MUON",
},
crypto: {
chainId: "gaia-13007",
networkId: "gaia-13007",
slip44: 118,
bech32: "cosmos",
},
Expand All @@ -32,7 +32,7 @@ export const manifest = {
symbol: "LUNA",
},
crypto: {
chainId: "columbus-3",
networkId: "columbus-3",
slip44: 330,
bech32: "terra",
},
Expand All @@ -44,7 +44,7 @@ export const manifest = {
symbol: "LUNA",
},
crypto: {
chainId: "soju-0014",
networkId: "soju-0014",
slip44: 330,
bech32: "terra",
},
Expand Down
15 changes: 11 additions & 4 deletions packages/platform-sdk-atom/src/services/peer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Coins, Contracts, Exceptions } from "@arkecosystem/platform-sdk";
import { manifest } from "../manifest";

export class PeerService implements Contracts.PeerService {
public static async construct(opts: Contracts.KeyValuePair): Promise<PeerService> {
return new PeerService();
readonly #seeds: string[];

public constructor(network: string) {
this.#seeds = manifest.networks[network].hosts;
}

public static async construct(config: Coins.Config): Promise<PeerService> {
return new PeerService(config.get<string>("network"));
}

public async destruct(): Promise<void> {
//
}

public getSeeds(): Contracts.Peer[] {
throw new Exceptions.NotImplemented(this.constructor.name, "getSeeds");
public getSeeds(): string[] {
return this.#seeds;
}

public withVersion(version: string): PeerService {
Expand Down
6 changes: 4 additions & 2 deletions packages/platform-sdk-atom/src/services/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { Coins, Contracts, Exceptions } from "@arkecosystem/platform-sdk";
import { createSignedTransaction } from "../utils/crypto";
import { ClientService } from "./client";
import { IdentityService } from "./identity";
import { manifest } from "../manifest";

export class TransactionService implements Contracts.TransactionService {
readonly #client;
readonly #identity;
readonly #chainId = "gaia-13007"; // todo: make this configurable, currently uses testnet
readonly #networkId;

private constructor(opts: Contracts.KeyValuePair) {
this.#client = opts.client;
this.#identity = opts.identity;
this.#networkId = manifest.networks[opts.network].crypto.networkId;
}

public static async construct(config: Coins.Config): Promise<TransactionService> {
Expand Down Expand Up @@ -52,7 +54,7 @@ export class TransactionService implements Contracts.TransactionService {
},
},
],
chain_id: this.#chainId, // todo: make this configurable
chain_id: this.#networkId,
fee: {
amount: [
{
Expand Down
15 changes: 11 additions & 4 deletions packages/platform-sdk-btc/src/services/peer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Coins, Contracts, Exceptions } from "@arkecosystem/platform-sdk";
import { manifest } from "../manifest";

export class PeerService implements Contracts.PeerService {
public static async construct(opts: Contracts.KeyValuePair): Promise<PeerService> {
return new PeerService();
readonly #seeds: string[];

public constructor(network: string) {
this.#seeds = manifest.networks[network].hosts;
}

public static async construct(config: Coins.Config): Promise<PeerService> {
return new PeerService(config.get<string>("network"));
}

public async destruct(): Promise<void> {
//
}

public getSeeds(): Contracts.Peer[] {
throw new Exceptions.NotImplemented(this.constructor.name, "getSeeds");
public getSeeds(): string[] {
return this.#seeds;
}

public withVersion(version: string): PeerService {
Expand Down
Loading

0 comments on commit 17183fa

Please sign in to comment.