This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/db.rake | |
namespace :db do | |
desc "Dumps the database to db/APP_NAME.dump" | |
task :dump => :environment do | |
cmd = nil | |
with_config do |app, host, db, user| | |
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump" | |
end | |
puts cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function watchEtherTransfers() { | |
// Instantiate web3 with WebSocket provider | |
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws')) | |
// Instantiate subscription object | |
const subscription = web3.eth.subscribe('pendingTransactions') | |
// Subscribe to pending transactions | |
subscription.subscribe((error, result) => { | |
if (error) console.log(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function watchTokenTransfers() { | |
// Instantiate web3 with WebSocketProvider | |
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws')) | |
// Instantiate token contract object with JSON ABI and address | |
const tokenContract = new web3.eth.Contract( | |
TOKEN_ABI, process.env.TOKEN_CONTRACT_ADDRESS, | |
(error, result) => { if (error) console.log(error) } | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getConfirmations(txHash) { | |
try { | |
// Instantiate web3 with HttpProvider | |
const web3 = new Web3('https://rinkeby.infura.io/') | |
// Get transaction details | |
const trx = await web3.eth.getTransaction(txHash) | |
// Get current block number | |
const currentBlock = await web3.eth.getBlockNumber() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function confirmEtherTransaction(txHash, confirmations = 10) { | |
setTimeout(async () => { | |
// Get current number of confirmations and compare it with sought-for value | |
const trxConfirmations = await getConfirmations(txHash) | |
console.log('Transaction with hash ' + txHash + ' has ' + trxConfirmations + ' confirmation(s)') | |
if (trxConfirmations >= confirmations) { | |
// Handle confirmation event according to your business logic |