Coder Social home page Coder Social logo

filter-exercise-jsong-pb-sf-072618's Introduction

Loading a Bloom Filter

Do the following:

  • Connect to a testnet node
  • Load a filter for your testnet address
  • Send a request for transactions from the block which had your previous testnet transaction
  • Receive the merkleblock and tx messages.
# Exercise 2.2

from bloomfilter import BloomFilter, BIP37_CONSTANT
from helper import (
    bit_field_to_bytes,
    decode_base58,
    hash160,
    hash256,
    little_endian_to_int,
    murmur3,
    run,
    SIGHASH_ALL,
)
from ecc import PrivateKey
from network import (
    GetDataMessage,
    GetHeadersMessage,
    HeadersMessage,
    SimpleNode,
    FILTERED_BLOCK_DATA_TYPE,
    TX_DATA_TYPE,
)

block_hash = bytes.fromhex('<fill this in>')
passphrase = b'<fill this in>'  # FILL THIS IN
secret = little_endian_to_int(hash256(passphrase))
private_key = PrivateKey(secret=secret)
addr = private_key.point.address(testnet=True)
print(addr)
filter_size = 30
filter_num_functions = 5
filter_tweak = -1  # FILL THIS IN

# get the hash160 of the address using decode_base58
# create a bloom filter using the filter_size, filter_num_functions and filter_tweak above
# add the h160 to the bloom filter

# connect to tbtc.programmingblockchain.com in testnet mode, logging True
# complete the handshake
# send the filterload command with bf.filterload() as the payload
# create a getdata message
# add_data (FILTERED_BLOCK_DATA_TYPE, block_hash) to request the block
# send the getdata message
# wait for the merkleblock command
# wait for the tx command
# print the envelope payload in hex

filter-exercise-jsong-pb-sf-072618's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.