Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typings for js xdr memo network #219

Merged
merged 4 commits into from
Jul 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add typings for network.
  • Loading branch information
abuiles committed Jul 30, 2019
commit 7a1b03290bcbd168565cfad4218f4909ccd7d2d7
25 changes: 16 additions & 9 deletions src/network.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { hash } from './hashing';

interface Networks {
PUBLIC: string;
TESTNET: string;
}

/**
* Contains passphrases for common networks:
* * `Networks.PUBLIC`: `Public Global Stellar Network ; September 2015`
* * `Networks.TESTNET`: `Test SDF Network ; September 2015`
* @type {{PUBLIC: string, TESTNET: string}}
*/
export const Networks = {
export const Networks: Networks = {
PUBLIC: 'Public Global Stellar Network ; September 2015',
TESTNET: 'Test SDF Network ; September 2015'
};

let current = null;
let current: Network | null = null;

/**
* The Network class provides helper methods to get the passphrase or id for different
@@ -26,23 +31,25 @@ let current = null;
* @param {string} networkPassphrase Network passphrase
*/
export class Network {
constructor(networkPassphrase) {
private _networkPassphrase: string;

constructor(networkPassphrase: string) {
this._networkPassphrase = networkPassphrase;
}

/**
* Use Stellar Public Network
* @returns {void}
*/
static usePublicNetwork() {
static usePublicNetwork(): void {
this.use(new Network(Networks.PUBLIC));
}

/**
* Use test network.
* @returns {void}
*/
static useTestNetwork() {
static useTestNetwork(): void {
this.use(new Network(Networks.TESTNET));
}

@@ -51,28 +58,28 @@ export class Network {
* @param {Network} network Network to use
* @returns {void}
*/
static use(network) {
static use(network: Network): void {
current = network;
}

/**
* @returns {Network} Currently selected network
*/
static current() {
static current(): Network | null {
return current;
}

/**
* @returns {string} Network passphrase
*/
networkPassphrase() {
public networkPassphrase(): string {
return this._networkPassphrase;
}

/**
* @returns {string} Network ID (SHA-256 hash of network passphrase)
*/
networkId() {
public networkId(): Buffer {
return hash(this.networkPassphrase());
}
}