Skip to content
Snippets Groups Projects
Commit 7026c9c3 authored by Millicent Billette's avatar Millicent Billette
Browse files

WiP: network client

parent 502cfbce
No related branches found
No related tags found
No related merge requests found
......@@ -3028,6 +3028,14 @@
"sha.js": "^2.4.8"
}
},
"cross-fetch": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz",
"integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==",
"requires": {
"node-fetch": "2.6.1"
}
},
"cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
......@@ -7474,6 +7482,11 @@
"integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw==",
"dev": true
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"node-libs-browser": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz",
......
......@@ -37,8 +37,10 @@
"watch2null": "chokidar src/* -c \"npm run test:dev:runTests 2>/dev/null\""
},
"dependencies": {
"cross-fetch": "^3.1.4",
"js-sha256": "https://github.com/1000i100/js-sha256#master",
"latinize-to-ascii": "^0.5.2",
"node-fetch": "^2.6.1",
"scrypt-async-modern": "^3.0.12",
"tweetnacl": "^1.0.3"
},
......
export {};
import fetch from 'node-fetch';
export function DataPodClient(hosts){
const self = this;
self.hosts = hosts;
self.query = queryStr => query(self,queryStr)
return self;
}
async function query(self,queryStr){
return await (await fetch(self.hosts[0]+queryStr)).json();
}
import test from 'ava';
import * as app from './data-pod-client.mjs';
test.skip('data-pod-client real server request', async t => {
test('data-pod-client real server request', async t => {
const hosts = ['https://g1.data.e-is.pro/'];
const query = 'user/profile/2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT?&_source=title';
const expectedResult = JSON.parse(`{
......
export {};
import fetch from 'node-fetch';
export function GvaClient(hosts){
const self = this;
self.hosts = hosts;
self.query = queryStr => query(self,queryStr)
return self;
}
async function query(self,queryStr){
return await (await fetch(self.hosts[0],{method: 'POST',body:queryStr})).json();
}
import test from 'ava';
import * as app from './gva-client.mjs';
test('dummy', async t => {
t.true(true);
// TODO: handle GVASUB in gva-ws-client.mjs
// subscription{newBlocks{number}}
test('gva real server request', async t => {
const hosts = ['https://g1.librelois.fr/gva'];
const query = '{"query":"query($pubkey: PkOrScriptGva!) { balance(script: $pubkey) { amount }}","variables":{"pubkey":"2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT"}}';
// Unused result example : `{ "data": { "balance": { "amount": 0 } } }`
const client = new app.GvaClient(hosts);
const result = await client.query(query);
t.true(result.data.balance.amount > 0);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment