Esempio n. 1
0
def get_block_range_for_timestamps(provider_uri, start_timestamp, end_timestamp, output, chain='ethereum'):
    """Outputs start and end blocks for given timestamps."""
    provider_uri = check_classic_provider_uri(chain, provider_uri)
    provider = get_provider_from_uri(provider_uri)
    web3 = build_web3(provider)
    eth_service = EthService(web3)

    start_block, end_block = eth_service.get_block_range_for_timestamps(start_timestamp, end_timestamp)

    with smart_open(output, 'w') as output_file:
        output_file.write('{},{}\n'.format(start_block, end_block))
Esempio n. 2
0
    type=str,
    help='The URI of the web3 provider e.g. '
    'file://$HOME/Library/Ethereum/geth.ipc or https://mainnet.infura.io')
parser.add_argument('-s',
                    '--start-timestamp',
                    required=True,
                    type=int,
                    help='Start unix timestamp, in seconds.')
parser.add_argument('-e',
                    '--end-timestamp',
                    required=True,
                    type=int,
                    help='End unix timestamp, in seconds.')
parser.add_argument('-o',
                    '--output',
                    default='-',
                    type=str,
                    help='The output file. If not specified stdout is used.')

args = parser.parse_args()

provider = get_provider_from_uri(args.provider_uri)
web3 = Web3(provider)
eth_service = EthService(web3)

start_block, end_block = eth_service.get_block_range_for_timestamps(
    args.start_timestamp, args.end_timestamp)

with smart_open(args.output, 'w') as output_file:
    output_file.write('{},{}\n'.format(start_block, end_block))