Ejemplo n.º 1
0
def refund(transaction, sender_address, amount, version, network):
    try:
        click.echo(
            RefundTransaction(version=version,
                              network=network).build_transaction(
                                  transaction_id=transaction,
                                  wallet=Wallet(network=network).from_address(
                                      address=sender_address),
                                  amount=int(amount)).unsigned_raw())
    except Exception as exception:
        click.echo(click.style("Error: {}").format(str(exception)), err=True)
        sys.exit()
Ejemplo n.º 2
0
def fund(sender_address, amount, bytecode, version, network):
    try:
        click.echo(
            FundTransaction(version=version,
                            network=network).build_transaction(
                                wallet=Wallet(network=network).from_address(
                                    address=sender_address),
                                htlc=HTLC(network=network).from_bytecode(
                                    bytecode=bytecode),
                                amount=int(amount)).unsigned_raw())
    except Exception as exception:
        click.echo(click.style("Error: {}").format(str(exception)), err=True)
        sys.exit()
Ejemplo n.º 3
0
def test_from_address():
    # testing from address
    address = "mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE"

    # Initialize bitcoin wallet
    bitcoin_from_address = Wallet(network="testnet").from_address(address)

    assert bitcoin_from_address.address() == address

    _hash = "6bce65e58a50b97989930e9a4ff1ac1a77515ef1"
    assert bitcoin_from_address.hash() == _hash

    p2pkh = "76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac"
    assert bitcoin_from_address.p2pkh() == p2pkh

    p2sh = "a914347283eee92ad685909044619adaa70370b2538787"
    assert bitcoin_from_address.p2sh() == p2sh
Ejemplo n.º 4
0
#!/usr/bin/env python3

from shuttle.providers.bitcoin.wallet import Wallet
from shuttle.providers.bitcoin.transaction import ClaimTransaction
from shuttle.providers.bitcoin.solver import ClaimSolver
from shuttle.providers.bitcoin.signature import ClaimSignature, Signature

network = "testnet"
recipient_passphrase = "meheret".encode()

# Initialize recipient bitcoin wallet
recipient_wallet = Wallet(network=network)\
    .from_passphrase(recipient_passphrase)
recipient_private_key = recipient_wallet.private_key()
# Funded hash time lock contract transaction id/hash
fund_transaction_id = "91f3a0dc0621f78be74a971dfb35d75255426d273f766456d9975006ece78b88"


# Testing bitcoin claim
def test_bitcoin_claim():
    # Initialization claim transaction
    unsigned_claim_transaction = ClaimTransaction(version=2, network=network)
    # Building claim transaction
    unsigned_claim_transaction.build_transaction(
        transaction_id=fund_transaction_id,
        wallet=recipient_wallet,
        amount=2000)

    assert unsigned_claim_transaction.fee == 576
    assert unsigned_claim_transaction.hash(
    ) == "726e390af02215d346be089dff566ae070f7332e8927d83acbb40b0e9105a787"
Ejemplo n.º 5
0
from shuttle.providers.bitcoin.signature import FundSignature
from shuttle.utils import sha256

import json

# Setting network
# mainnet or testnet
network = "testnet"

print("=" * 10, "Sender Bitcoin Account")

sender_passphrase = "meheret tesfaye batu bayou".encode()
print("Sender Passphrase:", sender_passphrase.decode())

# Initialize sender bitcoin wallet
sender_wallet = Wallet(network=network)
sender_wallet.from_passphrase(sender_passphrase)
# Getting wallet information's
sender_private_key = sender_wallet.private_key()
print("Sender Private Key:", sender_private_key)
sender_public_key = sender_wallet.public_key()
print("Sender Public Key:", sender_public_key)
sender_compressed = sender_wallet.compressed()
print("Sender Compressed:", sender_compressed)
sender_uncompressed = sender_wallet.uncompressed()
print("Sender Uncompressed:", sender_uncompressed)
sender_address = sender_wallet.address()
print("Sender Address:", sender_address)
sender_hash = sender_wallet.hash()
print("Sender Hash:", sender_hash)
sender_p2pkh = sender_wallet.p2pkh()
Ejemplo n.º 6
0
from shuttle.providers.bitcoin.solver import ClaimSolver
from shuttle.providers.bitcoin.signature import ClaimSignature

import json

# Setting network
# mainnet or testnet
network = "testnet"

print("=" * 10, "Recipient Bitcoin Account")

recipient_passphrase = "meheret".encode()
print("Recipient Passphrase:", recipient_passphrase.decode())

# Initialize recipient bitcoin wallet
recipient_wallet = Wallet(network=network)\
    .from_passphrase(recipient_passphrase)
recipient_private_key = recipient_wallet.private_key()
print("Recipient Private Key:", recipient_private_key)
recipient_public_key = recipient_wallet.public_key()
print("Recipient Public Key:", recipient_public_key)
recipient_compressed = recipient_wallet.compressed()
print("Recipient Compressed:", recipient_compressed)
recipient_uncompressed = recipient_wallet.uncompressed()
print("Recipient Uncompressed:", recipient_uncompressed)
recipient_address = recipient_wallet.address()
print("Recipient Address:", recipient_address)
recipient_hash = recipient_wallet.hash()
print("Recipient Hash:", recipient_hash)
recipient_p2pkh = recipient_wallet.p2pkh()
print("Recipient P2PKH:", recipient_p2pkh)
recipient_p2sh = recipient_wallet.p2sh()
Ejemplo n.º 7
0
#!/usr/bin/env python3

from shuttle.providers.bitcoin.wallet import Wallet
from shuttle.providers.bitcoin.transaction import RefundTransaction
from shuttle.providers.bitcoin.solver import RefundSolver
from shuttle.providers.bitcoin.signature import RefundSignature, Signature

network = "testnet"
sender_passphrase = "meheret".encode()

# Initialize sender bitcoin wallet
sender_wallet = Wallet(network=network)\
    .from_passphrase(sender_passphrase)
sender_private_key = sender_wallet.private_key()
# Initialize recipient bitcoin wallet
recipient_wallet = Wallet(network=network)
recipient_wallet.from_address("muTnffLDR5LtFeLR2i3WsKVfdyvzfyPnVB")
recipient_address = recipient_wallet.address()
# Funded hash time lock contract transaction id/hash
fund_transaction_id = "91f3a0dc0621f78be74a971dfb35d75255426d273f766456d9975006ece78b88"


# Testing bitcoin refund
def test_bitcoin_refund():
    # Initialization refund transaction
    unsigned_refund_transaction = RefundTransaction(version=2, network=network)
    # Building refund transaction
    unsigned_refund_transaction.build_transaction(
        transaction_id=fund_transaction_id,
        wallet=recipient_wallet,
        amount=2000
Ejemplo n.º 8
0
# Bitcoin network
NETWORK = "testnet"
# Bitcoin transaction id/hash
TRANSACTION_ID = "31507decc14a0f334f5de2329f828f4e22017f7333add9579bb2e889203b7135"
# Recipient passphrase/password
RECIPIENT_PASSPHRASE = "Woo!"
# Sender Bitcoin address
SENDER_ADDRESS = "miAcLpYbaqE8KowBu2PwvqXG6y6vpQcfTJ"
# Bitcoin claim amount
AMOUNT = 10_000

print("=" * 10, "Recipient Bitcoin Account")

# Initializing recipient Bitcoin wallet
recipient_wallet = Wallet(network=NETWORK)
# Initializing Bitcoin wallet from passphrase
recipient_wallet.from_passphrase(passphrase=RECIPIENT_PASSPHRASE)
# Getting recipient wallet information's
recipient_private_key = recipient_wallet.private_key()
print("Recipient Private Key:", recipient_private_key)
recipient_public_key = recipient_wallet.public_key()
print("Recipient Public Key:", recipient_public_key)
recipient_compressed = recipient_wallet.compressed()
print("Recipient Compressed:", recipient_compressed)
recipient_uncompressed = recipient_wallet.uncompressed()
print("Recipient Uncompressed:", recipient_uncompressed)
recipient_address = recipient_wallet.address()
print("Recipient Address:", recipient_address)
recipient_hash = recipient_wallet.hash()
print("Recipient Hash:", recipient_hash)
Ejemplo n.º 9
0
def test_from_private_key():
    # testing from private keky
    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"

    # Initialize bitcoin wallet
    bitcoin_from_private_key = Wallet(network="testnet")\
        .from_private_key(private_key)

    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    assert bitcoin_from_private_key.private_key() == private_key

    public_key = "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    assert bitcoin_from_private_key.public_key() == public_key

    address = "mphBPZf15cRFcL5tUq6mCbE84XobZ1vg7Q"
    assert bitcoin_from_private_key.address() == address

    # Initialize bitcoin wallet
    bitcoin_from_private_key = Wallet(network="testnet") \
        .from_private_key(private_key, False)

    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    assert bitcoin_from_private_key.private_key() == private_key

    public_key = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c9659" \
                 "94963c77bfb470dff5afd351a442ebf329f3b2c2835"
    assert bitcoin_from_private_key.public_key() == public_key

    compressed = "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    assert bitcoin_from_private_key.compressed() == compressed

    uncompressed = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c96" \
                   "5994963c77bfb470dff5afd351a442ebf329f3b2c2835"
    assert bitcoin_from_private_key.uncompressed() == uncompressed

    assert bitcoin_from_private_key.uncompressed() == bitcoin_from_private_key.public_key()

    address = "mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE"
    assert bitcoin_from_private_key.address() == address

    _hash = "6bce65e58a50b97989930e9a4ff1ac1a77515ef1"
    assert bitcoin_from_private_key.hash() == _hash

    p2pkh = "76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac"
    assert bitcoin_from_private_key.p2pkh() == p2pkh

    p2sh = "a914347283eee92ad685909044619adaa70370b2538787"
    assert bitcoin_from_private_key.p2sh() == p2sh
Ejemplo n.º 10
0
def test_bitcoin_wallet_tools():
    wallet = Wallet(network="testnet")
    private_key = "92cbbc5990cb5090326a76feeb321cad01048635afe5756523bbf9f7a75bf38b"
    public_key = wallet.public_key(private_key=private_key)
    assert public_key == "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    public_key = "04c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84fee63d89a5979801c96" \
                 "5994963c77bfb470dff5afd351a442ebf329f3b2c2835"

    compressed = wallet.compressed(public_key=public_key)
    assert compressed == "03c56a6005d4a8892d28cc3f7265e5685b548627d59108973e474c4e26f69a4c84"
    uncompressed = wallet.uncompressed(public_key=public_key)
    assert uncompressed == public_key
    address = wallet.address(public_key=uncompressed)
    assert address == "mqLyrNDjpENRMZAoDpspH7kR9RtgvhWzYE"
    _hash = wallet.hash(public_key=uncompressed)
    assert _hash == "6bce65e58a50b97989930e9a4ff1ac1a77515ef1"
    p2pkh = wallet.p2pkh(address=address)
    assert p2pkh == "76a9146bce65e58a50b97989930e9a4ff1ac1a77515ef188ac"
    p2sh = wallet.p2sh(address=address)
    assert p2sh == "a914347283eee92ad685909044619adaa70370b2538787"
    balance = wallet.balance(address=address, network="testnet")
    assert isinstance(balance, int)
    unspent = wallet.unspent(address=address, network="testnet", limit=1)
    assert isinstance(unspent, list)
Ejemplo n.º 11
0
#!/usr/bin/env python3

from shuttle.providers.bitcoin.wallet import Wallet
from shuttle.cli.__main__ import main as cli_main
from shuttle.utils import sha256

network = "testnet"
sender_wallet = Wallet(
    network=network).from_passphrase("meheret tesfaye batu bayou")
recipient_wallet = Wallet(network=network).from_passphrase("meheret")
secret_hash = sha256("Hello Meheret!".encode()).hex()
sequence = 1000


def test_bitcoin_cli_htlc(cli_tester):

    htlc = cli_tester.invoke(cli_main, [
        "bitcoin", "htlc", "--secret-hash", secret_hash, "--recipient-address",
        recipient_wallet.address(), "--sender-address",
        sender_wallet.address(), "--sequence", sequence, "--network", network
    ])
    assert htlc.exit_code == 0
    assert htlc.output == "63aa20821124b554d13f247b1e5d10b84e44fb1296f18f38bbaa1bea34a12c843e01588876a91498f8" \
                          "79fb7f8b4951dee9bc8a0327b792fbe332b888ac6702e803b27576a91464a8390b0b1685fcbf2d4b45" \
                          "7118dc8da92d553488ac68" + "\n"

    htlc = cli_tester.invoke(cli_main, [
        "bitcoin", "htlc", "--secret-hash", secret_hash, "--recipient-address",
        "L5tUq6mCbE84XobZ1mphBPZf15cRFcvg7Q", "--sender-address",
        sender_wallet.address(), "--sequence", sequence, "--network", network
    ])