Skip to content

Commit

Permalink
Merge pull request #133 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
v8.6.0
  • Loading branch information
Gabriel Cardona authored Jul 30, 2019
2 parents fbed68e + 1d9484f commit 781e24f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/BITBOX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// imports
import { Address } from "./Address"
import { BitcoinCash } from "./BitcoinCash"
import { BitDB } from "./BitDB"
import { Block } from "./Block"
import { Blockchain } from "./Blockchain"
import { CashAccounts } from "./CashAccounts"
Expand All @@ -29,12 +30,16 @@ export const WS_URL = "wss://ws.bitcoin.com"
export const TWS_URL = "wss://tws.bitcoin.com"
export const REST_URL = "https://rest.bitcoin.com/v2/"
export const TREST_URL = "https://trest.bitcoin.com/v2/"
export const BITDB_URL = "https://bitdb.bitcoin.com/"
export const TBITDB_URL = "https://tbitdb.bitcoin.com/"

export class BITBOX {
public restURL: string
public bitdbURL: string
public wsURL: string
public Address: Address
public BitcoinCash: BitcoinCash
public BitDB: BitDB
public Block: Block
public Blockchain: Blockchain
public CashAccounts: CashAccounts
Expand Down Expand Up @@ -62,8 +67,13 @@ export class BITBOX {
if (config && config.wsURL && config.wsURL !== "") this.wsURL = config.wsURL
else this.wsURL = WS_URL

if (config && config.bitdbURL && config.bitdbURL !== "")
this.bitdbURL = config.bitdbURL
else this.bitdbURL = BITDB_URL

this.Address = new Address(this.restURL)
this.BitcoinCash = new BitcoinCash(this.Address)
this.BitDB = new BitDB(this.bitdbURL)
this.Block = new Block(this.restURL)
this.Blockchain = new Blockchain(this.restURL)
this.CashAccounts = new CashAccounts(this.restURL)
Expand Down
27 changes: 27 additions & 0 deletions lib/BitDB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// imports
import axios, { AxiosResponse } from "axios"
import { BITDB_URL } from "./BITBOX"
import { BitDBResponse, QueryInterface } from "./interfaces/BITBOXInterfaces"

// consts
const Buffer = require("safe-buffer").Buffer

export class BitDB {
public bitdbURL: string
constructor(bitdbURL: string = BITDB_URL) {
this.bitdbURL = bitdbURL
}

public async get(query: QueryInterface): Promise<BitDBResponse> {
try {
const s: string = JSON.stringify(query)
const b64: string = Buffer.from(s).toString("base64")
const url: string = `${this.bitdbURL}q/${b64}`
const tokenRes: AxiosResponse = await axios.get(url)
return tokenRes.data
} catch (error) {
if (error.response && error.response.data) throw error.response.data
else throw error
}
}
}
11 changes: 11 additions & 0 deletions lib/interfaces/BITBOXInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
export interface IConfig {
restURL?: string
wsURL?: string
bitdbURL?: string
}

export interface SocketConfig {
restURL?: string
wsURL?: string
callback?: Function
}

export interface QueryInterface {
amount?: number
label?: string
message?: string
}

export interface BitDBResponse {
message: string
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitbox-sdk",
"version": "8.5.1",
"version": "8.6.0",
"description": "BITBOX SDK for Bitcoin Cash",
"author": "Gabriel Cardona <gabriel@bitcoin.com>",
"contributors": [
Expand Down

0 comments on commit 781e24f

Please sign in to comment.