Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
version: VERSION,
toAddr,
amount: units.toQa(amount, units.Units.Zil),
gasPrice: new BN(minGasPriceInQa),
gasLimit: Long.fromNumber(1),
pubKey: publicKey,
nonce
},
provider
);
const signedTx = yield wallet.sign(tx);
const { txParams } = signedTx;
// Send a transaction to the network
const data = yield provider.send(RPCMethod.CreateTransaction, txParams);
if (data.error !== undefined) {
throw Error(data.error.message);
}
const sendTxId = data.result.TranID;
yield put({
type: consts.SEND_TX_SUCCEEDED,
payload: { sendTxId }
});
} catch (error) {
console.log(error);
yield put({ type: consts.SEND_TX_FAILED });
}
}
{
version: VERSION,
toAddr,
amount,
gasPrice,
gasLimit,
pubKey,
nonce
},
provider
);
const signedTx = await wallet.sign(tx);
const { txParams } = signedTx;
// Send a transaction to the network
const tsRes = await provider.send(RPCMethod.CreateTransaction, txParams);
const { result } = tsRes;
const txId = result && result.TranID;
if (txId === undefined) {
console.log('Response', tsRes);
throw Error('No TxID!');
}
console.log(`TxID: ${txId}`);
const now = Date.now();
const userData = {
claimed_at: now
};
await userRef.set(userData);
console.log(`Claimed at: ${now}`);
reject('User denied access!');
result.unsubscribe();
}
// Close stream by time.
setTimeout(() => {
result.unsubscribe();
reject(new Error('waiting time may have problems ZilPay'));
}, 15000);
});
});
}
}
window.zilPay = new ZilPay(new HTTPProvider(PROVIDER));
if (typeof window.Zilliqa !== 'undefined') {
console.error('window.Zilliqa already exists');
}
window.Zilliqa = Zilliqa;
export default function run() {
// Create instance in page. //
const type = MTypesSecure.PAY_OBJECT_INIT;
const recipient = MTypesSecure.CONTENT;
observableStream(
MTypesSecure.INJECTED,
public send = async ({ args }): Promise => {
const { amount, toAddress } = args;
const { wallet } = this.state;
const tx = new Transaction(await this.getParams(toAddress, amount), provider);
const signedTx = await wallet.sign(tx);
const { txParams } = signedTx;
// Send a transaction to the network
const res = await provider.send(RPCMethod.CreateTransaction, txParams);
if (res.error !== undefined) throw new Error(res.error.message);
return res.result ? res.result.TranID : undefined;
};
async signedTxSend(payload) {
const tx = await this.provider.send( // Send to shard node.
RPCMethod.CreateTransaction, payload
);
return tx;
}
const zilTxData = this.transactions.new({
nonce,
gasPrice,
amount,
gasLimit,
version,
toAddr,
pubKey,
code,
data
});
// Sign transaction by current account. //
const { txParams } = await this.wallet.sign(zilTxData);
return await this.provider.send( // Send to shard node.
RPCMethod.CreateTransaction, txParams
);
}
private async getBlockNumber(): Promise {
try {
const res: RPCResponse = await this.provider.send(
RPCMethod.GetLatestTxBlock,
);
if (res.error === undefined && res.result.header.BlockNum) {
// if blockNumber is too high, we use BN to be safer
return new BN(res.result.header.BlockNum);
} else {
throw new Error('Can not get latest BlockNumber');
}
} catch (error) {
throw error;
}
}
result.unsubscribe();
resolve(
Object.assign(tx, resultTx.resolve)
);
}
// Close stream by time.
setTimeout(() => {
result.unsubscribe();
reject(new Error('waiting time may have problems ZilPay'));
}, 9000);
});
});
}
HTTPProvider.prototype.send = (method, params) => {
const type = MTypesZilPay.PROXY_MEHTOD;
const recipient = MTypesSecure.CONTENT;
const uuid = uuidv4();
new SecureMessage({
type, payload: { params, method, uuid }
}).send(stream, recipient);
return new Promise((resolve, reject) => {
const proxy = subjectStream.subscribe(result => {
if (!result.uuid || result.uuid !== uuid) {
return null;
} else if (result.error) {
reject(result.error);
} else {
this.toAddr = normaliseAddress(params.toAddr);
this.nonce = params.nonce;
this.pubKey = params.pubKey;
this.amount = params.amount;
this.code = params.code || '';
this.data = params.data || '';
this.signature = params.signature;
this.gasPrice = params.gasPrice;
this.gasLimit = params.gasLimit;
this.receipt = params.receipt;
// public members
this.provider = provider;
this.status = status;
this.toDS = toDS;
this.blockConfirmation = 0;
this.eventEmitter = new EventEmitter();
}
const RECAPTCHA_SECRET = functions.config().faucet.recaptcha_secret;
const PRIVATE_KEY = functions.config().faucet.private_key;
const PUBLIC_KEY = getPubKeyFromPrivateKey(PRIVATE_KEY);
const ADDRESS = getAddressFromPrivateKey(PRIVATE_KEY);
const CHAIN_ID: number =
process.env.REACT_APP_CHAIN_ID !== undefined ? parseInt(process.env.REACT_APP_CHAIN_ID, 10) : 0;
const MSG_VERSION: number =
process.env.REACT_APP_MSG_VERSION !== undefined
? parseInt(process.env.REACT_APP_MSG_VERSION, 10)
: 0;
const VERSION = bytes.pack(CHAIN_ID, MSG_VERSION);
const NODE_URL: string = process.env.REACT_APP_NODE_URL || '';
const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);
zilliqa.wallet.addByPrivateKey(PRIVATE_KEY);
app.post('/run', async (req, res) => {
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(`IP address: ${ip}`);
console.log(`${NODE_URL}, ${CHAIN_ID}, ${MSG_VERSION}`);
const { token, address } = req.body;
try {
const verificationUrl =
'https://www.google.com/recaptcha/api/siteverify?secret=' +
RECAPTCHA_SECRET +
'&response=' +
token +