Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import fetch from 'node-fetch'
import { TextDecoder, TextEncoder } from 'util'
import { EosAction, TransactionActions } from '../../interfaces'
import { StateHistoryPostgresAbiProvider } from './StateHistoryPostgresAbiProvider'
// Wrapper to deal with differences between the definitions of fetch for the browser built-in
// and the node-fetch polyfill for node
// Is there a better way to do this?
const fetchWrapper = (input?: string | Request, init?: RequestInit): Promise => {
const anyInput = input as any
const anyInit = init as any
return fetch(anyInput, anyInit) as any
}
const signatureProvider = new JsSignatureProvider([])
const rpc = new JsonRpc('', { fetch: fetchWrapper } )
const abiProvider = new StateHistoryPostgresAbiProvider()
const api = new Api({
rpc,
abiProvider,
signatureProvider,
textDecoder: new TextDecoder(),
textEncoder: new TextEncoder()
})
const getApi = (blockNumber: number, massiveInstance: any, dbSchema: string, log: Logger) => {
const instanceAbiProvider = api.abiProvider as StateHistoryPostgresAbiProvider
instanceAbiProvider.setState(blockNumber, massiveInstance, dbSchema, log)
return api
}
export class StateHistoryPostgresBlock implements Block {
import fetch from 'node-fetch'
import { TextDecoder, TextEncoder } from 'util'
import { EosAction, TransactionActions } from '../../'
import { StateHistoryPostgresAbiProvider } from './StateHistoryPostgresAbiProvider'
// Wrapper to deal with differences between the definitions of fetch for the browser built-in
// and the node-fetch polyfill for node
// Is there a better way to do this?
const fetchWrapper = (input?: string | Request, init?: RequestInit): Promise => {
const anyInput = input as any
const anyInit = init as any
return fetch(anyInput, anyInit) as any
}
const signatureProvider = new JsSignatureProvider([])
const rpc = new JsonRpc('', { fetch: fetchWrapper } )
const abiProvider = new StateHistoryPostgresAbiProvider()
const api = new Api({
rpc,
abiProvider,
signatureProvider,
textDecoder: new TextDecoder(),
textEncoder: new TextEncoder()
})
const getApi = (blockNumber: number, massiveInstance: any, dbSchema: string, log: Logger) => {
const instanceAbiProvider = api.abiProvider as StateHistoryPostgresAbiProvider
instanceAbiProvider.setState(blockNumber, massiveInstance, dbSchema, log)
return api
}
export class StateHistoryPostgresBlock implements Block {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
endpoint = query.endpoint, account_name = query.account_name;
rpc = new eosjs_1.JsonRpc(endpoint);
return [4 /*yield*/, rpc.get_account(account_name)];
case 1:
result = _a.sent();
return [2 /*return*/, result];
case 2:
e_1 = _a.sent();
console.log('Caught exception: ' + e_1);
throw (e_1);
case 3: return [2 /*return*/];
}
});
}); };
export default async (query: {
endpoint: string,
account_name: string
}) => {
try{
let { endpoint, account_name } = query;
const rpc = new JsonRpc(endpoint);
const result = await rpc.get_account(account_name);
return result;
}catch(e){
console.log('Caught exception: ' + e);
throw(e);
}
}
export default async (query: { endpoint: string }) => {
try{
let { endpoint } = query;
const rpc = new JsonRpc(endpoint);
let response = await rpc.get_info();
return response;
}catch(e){
console.log('Caught exception: ' + e);
throw(e);
}
}
function setRpcApi(api) {
eosRPC = new JsonRpc(api, {fetch});
}
export default async (query: {
endpoint: string,
private_key: string,
actor: string,
permission: string,
new_account_name: string,
new_account_owner_key: string,
new_account_active_key: string
}) => {
try{
let { endpoint, private_key: creator_private_key, actor: creator_account_name, permission: creator_account_permission, new_account_name, new_account_owner_key, new_account_active_key } = query;
const rpc = new JsonRpc(endpoint);
const signatureProvider = new JsSignatureProvider([creator_private_key]);
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const result = await api.transact({
actions: [{
account: 'eosio',
name: 'newaccount',
authorization: [{
actor: creator_account_name,
permission: creator_account_permission,
}],
data: {
creator: creator_account_name,
name: new_account_name,
owner: {
threshold: 1,
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
endpoint = query.endpoint, creator_private_key = query.private_key, creator_account_name = query.actor, creator_account_permission = query.permission, new_account_name = query.new_account_name, new_account_owner_key = query.new_account_owner_key, new_account_active_key = query.new_account_active_key;
rpc = new eosjs_1.JsonRpc(endpoint);
signatureProvider = new eosjs_jssig_1.default([creator_private_key]);
api = new eosjs_1.Api({ rpc: rpc, signatureProvider: signatureProvider, textDecoder: new text_encoding_1.TextDecoder(), textEncoder: new text_encoding_1.TextEncoder() });
return [4 /*yield*/, api.transact({
actions: [{
account: 'eosio',
name: 'newaccount',
authorization: [{
actor: creator_account_name,
permission: creator_account_permission,
}],
data: {
creator: creator_account_name,
name: new_account_name,
owner: {
threshold: 1,
keys: [{
import * as ReactDOM from 'react-dom';
import * as IoClient from 'socket.io-client';
import { Key } from '../common/Key';
import { WaSignatureProvider } from './wasig';
require('./style.css');
const socketUrl = 'http://localhost:8000';
class AppState {
public alive = true;
public io: SocketIOClient.Socket;
public clientRoot: ClientRoot;
public keys = [] as Key[];
public sigprov = new WaSignatureProvider();
public rpc = new JsonRpc('http://localhost:8888');
public api: Api;
public message = '';
public balances = new Map();
constructor() {
this.api = new Api({ rpc: this.rpc, signatureProvider: this.sigprov });
this.updateBalance('usera');
this.updateBalance('userb');
this.updateBalance('userc');
this.updateBalance('userd');
}
public restore(prev: AppState) {
this.message = prev.message;
this.setKeys(prev.keys);
}