Giter Club home page Giter Club logo

btctxstore's Introduction

btctxstore

BuildLink CoverageLink LicenseLink IssuesLink

A library to read/write data to bitcoin transactions as nulldata outputs.

Installation

Install btctxstore lib

pip install btctxstore

Use fast native functions

There is experimental code that will call into OpenSSL for slow functions. To enable this, set (and export) environment variable PYCOIN_NATIVE=openssl.

$ export PYCOIN_NATIVE=openssl

storing data in nulldata outputs

Store data in blockchain in new transaction with nulldata output.

# from examples/store_nulldata.py
import binascii
from btctxstore import BtcTxStore

# Wallet used to pay for fee. Please do not spend the testnet coins is
# this wallet or the example will fail due to lack of funds.
wifs = ["cUZfG8KJ3BrXneg2LjUX4VoMg76Fcgx6QDiAZj2oGbuw6da8Lzv1"]

# use testnet and dont post tx to blockchain for example
api = BtcTxStore(testnet=True, dryrun=True)

# store data in blockchain as nulldata output (max 40bytes)
data = binascii.hexlify(b"github.com/F483/btctxstore")
txid = api.store_nulldata(data, wifs)
print(txid)

retrieving data from nulldata outputs

Retrieve transaction from blockchain and read data stored as nulldata output.

# from examples/retrieve_nulldata.py
from btctxstore import BtcTxStore

api = BtcTxStore(testnet=True, dryrun=True)  # use testing setup for example
txid = "987451c344c504d07c1fa12cfbf84b5346535da5154006f6dc8399a8fae127eb"
hexnulldata = api.retrieve_nulldata(txid)
print(hexnulldata)

sign/verify data (bitcoind compatible)

# from examples/signverify.py
import binascii
from btctxstore import BtcTxStore

api = BtcTxStore(testnet=True, dryrun=True)  # use testing setup for example
wif = api.create_key()  # create new private key
address = api.get_address(wif)  # get private key address
data = binascii.hexlify(b"messagetext")  # hexlify messagetext

# sign data with private key
signature = api.sign_data(wif, data)
print("signature:", signature)

# verify signature (no public or private key needed)
isvalid = api.verify_signature(address, signature, data)
print("valid signature" if isvalid else "invalid signature")

Split utxos

Split utxos of wallet unitil limit or max_outputs reached.

# from examples/split_utxos.py
from btctxstore import BtcTxStore

# Please do not spend the testnet coins is this wallet
# or the example will fail due to lack of funds.
wif = "cUZfG8KJ3BrXneg2LjUX4VoMg76Fcgx6QDiAZj2oGbuw6da8Lzv1"

# use testnet and dont post tx to blockchain for example
api = BtcTxStore(testnet=True, dryrun=True)

limit = 10000000  # 0.1BTC
txids = api.split_utxos(wif, limit)
print(txids)

btctxstore's People

Contributors

f483 avatar littleskunk avatar

Watchers

James Cloos avatar Christian Moss avatar Yuta Hoshino 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.