Demo entry 6758359

顶顶顶顶

   

Submitted by anonymous on Aug 13, 2018 at 14:42
Language: JavaScript. Code size: 1.0 kB.

var request = require('sync-request');
var domain = 'http://192.168.3.137:8080';

function get_single_block(block_id)
{
	var path = '/v1/chain/get_block';
	var url = domain + path;
	var data = {block_num_or_id:block_id};
	var post_data = JSON.stringify(data);
	var res_data = request('POST', url, {body:post_data,}).getBody();
	var res = JSON.parse(res_data);
	console.log(res);
	return res;
}

function get_page_block(start_block)
{
	var results = [];
	if(0 == start_block)
	{
		var info = get_info();
		start_block = info.head_block_num;
	}
	for(var i= 0; i < 20; i++)
	{
		if(start_block - i < 0)
		{
			break;
		}
		results.push(get_single_block(start_block - i));
	}
	return results;
}

function get_info()
{
	var path = '/v1/chain/get_info';
	var url = domain + path;
	var res_data = request('POST', url).getBody();
	var res = JSON.parse(res_data);
	console.log(res);
	return res;
}
var a = get_single_block(10);
var b = get_info();
var c = get_page_block(100,90);
console.log(c)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).