Skip to content

Commit

Permalink
Merge pull request #16 from Matvei-Vasily/change-get-to-post
Browse files Browse the repository at this point in the history
change fetch - get to post
  • Loading branch information
peerchemist committed Jan 27, 2020
2 parents 819f06c + da34208 commit e158d83
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/drivers/blockbook.ts
Expand Up @@ -23,6 +23,18 @@ export class BlockBookDriver implements driver.Driver {
return this.fetch(href).then((response) => response.json());
}

private async fetch_post(href: string, data: string): Promise<Response> {
const response = await fetch(`${this.url}/${href}`, {method: 'post', body: data});
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return response;
}

private fetchJson_post(href: string, data: string): Promise<any> {
return this.fetch_post(href, data).then((response) => response.json());
}

async *taggedTransactions(tag: Address): AsyncIterable<driver.TxId> {
const data = await this.fetchJson(`api/address/${tag.toString()}`);
if (typeof data === 'object' && data.transactions instanceof Array) {
Expand All @@ -44,7 +56,7 @@ export class BlockBookDriver implements driver.Driver {

async sendRawTransaction(tx: Buffer): Promise<driver.TxId> {
const hex = tx.toString('hex');
const data = await this.fetchJson(`api/sendtx/${hex}`);
const data = await this.fetchJson_post(`api/sendtx/`, hex);
if (typeof data === 'object' && data.result !== undefined) {
return data.result;
}
Expand Down

0 comments on commit e158d83

Please sign in to comment.