Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async (query: {
endpoint: string,
account_name: string,
private_key: string,
actor: string,
permission: string,
action_name: string,
payload: any
}) => {
try{
let { endpoint, account_name, private_key, actor, permission, action_name, payload } = query;
const rpc = new JsonRpc(endpoint);
const signatureProvider = new JsSignatureProvider([private_key]);
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
if (account_name === "eosio" && action_name==="setabi"){
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
});
let abi = payload.abi;
const abiDefinition = api.abiTypes.get('abi_def');
// need to make sure abi has every field in abiDefinition.fields
// otherwise serialize throws error
abi = abiDefinition!.fields.reduce(
(acc, { name: fieldName }) => Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abi,
);
async function claimGBM(account_name, private_key, permission, rpc) {
const signatureProvider = new JsSignatureProvider([private_key]);
const api = new Api({rpc, signatureProvider, textDecoder: TextDec, textEncoder: TextEnc});
// check current votes
const accountData = await rpc.get_account(account_name);
let _producers = [];
let _proxy = '';
if (accountData['voter_info']) {
if (accountData['voter_info']['proxy'] !== '') {
// voting on proxy
_proxy = accountData['voter_info']['proxy'];
} else {
// voting on producers
_producers = accountData['voter_info']['producers'];
}
}
const _actions = [];
async function deployContract(blockchainUrl, account_name, private_key, permission, wasm_path, abi_path){
if(blockchainUrl.indexOf("http://") < 0)
{
blockchainUrl = "http://" + blockchainUrl;
}
const rpc = new JsonRpc(blockchainUrl, { fetch });
const signatureProvider = new JsSignatureProvider([private_key]);
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const buffer = new Serialize.SerialBuffer({
textEncoder: api.textEncoder,
textDecoder: api.textDecoder,
});
const wasm = fs.readFileSync(wasm_path).toString('hex');
let abi = JSON.parse(fs.readFileSync(abi_path, 'utf8'));
const abiDefinition = api.abiTypes.get('abi_def');
// need to make sure abi has every field in abiDefinition.fields
// otherwise serialize throws error
abi = abiDefinition.fields.reduce(
(acc, { name: fieldName }) => Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
abi,
);
static init = ({ httpEndpoint, adminAccount, chainId }: InitArgs) => {
// Create eosio account and configure signature provider
EOSManager.adminAccount = adminAccount;
// If we have a key to sign with, go ahead and hook it up.
if (adminAccount.privateKey) {
EOSManager.signatureProvider = new JsSignatureProvider([adminAccount.privateKey]);
}
// Typecasting as any here to prevent a problem with the types disagreeing for fetch,
// when this is actually following the getting started docs on EOSJS.
EOSManager.rpc = new JsonRpc(httpEndpoint, { fetch: fetch as any });
EOSManager.api = new Api({
rpc: EOSManager.rpc,
chainId,
signatureProvider: EOSManager.signatureProvider,
// Same deal here, type mismatch when there really shouldn't be.
textDecoder: new TextDecoder() as any,
textEncoder: new TextEncoder() as any,
});
};
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 {
public actions: EosAction[] = []
public blockInfo: BlockInfo
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 {
public actions: EosAction[] = []
public blockInfo: BlockInfo
const config = require('./config');
const csv = require('csv-parser');
const fs = require('fs');
const {Api, JsonRpc} = require('eosjs');
const JsSignatureProvider = require('eosjs/dist/eosjs-jssig');
const fetch = require('node-fetch');
const {TextEncoder, TextDecoder} = require('util');
const entries = [], tx_actions = [], failed_batches = [];
const signatureProvider = new JsSignatureProvider.default([config.private_key]);
const rpc = new JsonRpc(config.endpoint, {fetch});
const api = new Api({rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder()});
const whitelist_contract = config.contract;
const process_batches = (async (tx_actions) => {
console.log(`Processing ${tx_actions.length} batches`)
while (tx_actions.length){
const actions = tx_actions.pop();
try {
const res = await api.transact({
actions
}, {blocksBehind: 3, expireSeconds: 180});
console.log(res);
}
catch (e){
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,
keys: [{
key: new_account_owner_key,
async processTrx(binaryData) {
const args = {
rpc: this.localRPC ,
authorityProvider: undefined ,
abiProvider: undefined ,
signatureProvider: this ,
chainId: undefined ,
textEncoder: undefined ,
textDecoder: undefined
};
const api = new Api ( args );
return await api.deserializeTransactionWithActions ( binaryData );
}
function createInstance(args) {
let endpoint = args[0];
let privateKeys = args[1];
let signatureProvider = new JsSignatureProvider(privateKeys);
let rpc = new JsonRpc(endpoint, { fetch });
let EOSApi = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
return {
EOSApi: EOSApi,
EOSRpc: rpc,
RpcError: RpcError,
Serialize: Serialize,
JsSignatureProvider: JsSignatureProvider
};
}