Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'
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
}
const [auth, publicKey] = this.trxFactory.getAuth();
// check current votes
const accountData = await this.eosjs.rpc.get_account(auth.actor);
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 claim_private_key = await this.keytar.getPassword('simpleos', this.claimPublicKey);
const signatureProvider = new JsSignatureProvider([claim_private_key]);
const rpc = this.eosjs.rpc;
const api = new Api({rpc, signatureProvider, textDecoder: new TextDecoder, textEncoder: new TextEncoder});
const _actions = [];
_actions.push({
account: 'eosio',
name: 'voteproducer',
authorization: [{
actor: auth.actor,
permission: 'claim',
}],
data: {
voter: auth.actor,
proxy: _proxy,
producers: _producers
},
});
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'
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
}
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'];
}
}
initAPI(key) {
this.JsSigProvider = new JsSignatureProvider ( [ key ] );
this.api = new Api ( {
rpc: this.rpc ,
signatureProvider: this.JsSigProvider ,
textDecoder: new TextDecoder () ,
textEncoder: new TextEncoder ()
} );
setTimeout ( () => {
this.JsSigProvider = null;
this.api = null;
} , 5000 );
}
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
};
}
public decodeAbis(abis: HexAbi[]): AbiInfo[] {
const signatureProvider = new JsSignatureProvider([])
const api = new EosApi({
rpc: this.rpc,
signatureProvider,
chainId: null,
abiProvider: this.abiProvider,
})
return abis.map(({ abi, ...rest }) => {
const uInt8Abi = Serialize.hexToUint8Array(abi)
return { abi: api.rawAbiToJson(uInt8Abi), ...rest }
})
}
}
constructor() {
const rpc = new JsonRpc(null)
const signatureProvider = new JsSignatureProvider([])
this.api = new EosApi({
rpc,
signatureProvider,
chainId: null,
})
this.api.transactionTypes = Serialize.getTypesFromAbi(Serialize.createInitialTypes(), assertAbi)
}