Giter VIP home page Giter VIP logo

clove's Introduction

Lamden Blockchain

Lamden is an open-source Python-based blockchain development platform designed to help developers create new blockchain applications and networks quickly and easily. With Lamden, developers can leverage the power of blockchain technology to create secure and decentralized applications.

Features

  • Quick and easy setup: Lamden provides a suite of tools and infrastructure to help developers get started with blockchain development quickly and easily.
  • Flexible and customizable: Lamden is designed to be flexible and customizable, so developers can tailor it to meet their specific needs and requirements.
  • Secure and decentralized: Lamden is built on the principles of security and decentralization, so applications developed with Lamden are secure and decentralized by default.

Getting Started

Getting started with Lamden is easy. Our team has produced a great documentation which you can check out here.

Community

Join the Lamden community to connect with other developers and get help and support. You can find us on:

Contributions

Lamden is an open-source project, and contributions are welcome. If you're interested in contributing, check out our contribution guidelines to get started.

clove's People

Contributors

cmcgrath13 avatar jaworows avatar pafff avatar stuartfarmer avatar szerepak avatar trojkat avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clove's Issues

Create access to wallet via network

btc_network = TestNetBitcoin()

Create new wallet:

my_wallet = btc_network.get_new_wallet()

Get wallet from private key:

my_wallet = btc_network.get_wallet(my_private_key)

Get wallet from encrypted private key

my_wallet = btc_network.get_wallet(my_encrypted_private_key, passphrase)

Getting current fee estimates

The Problem

  • When creating a transaction we have to know the current fee value in the network to be able to create a transaction that will be included in the next block because with atomic swaps time matters.
  • Bitcoin nodes may also set the FeeFilter and do not accept transactions with fee rate lower than a specific value so again we need to set the right fee.
  • There is no way to get fee estimates using bitcoin P2P network protocol.

Solution 1

Use 3rd party API (like blockcypher.com) to get the current fee estimates.

In [1]: import requests

In [2]: r = requests.get('https://api.blockcypher.com/v1/btc/main').json()

In [3]: r
Out[3]: 
{'hash': '0000000000000000004e6a1ac1a65bfa801ad6b66d1641f2922311a410e176d1',
 'height': 507242,
 'high_fee_per_kb': 200801,
 'last_fork_hash': '00000000000000000055580862147720e31c3a8b80add74b0a77059a66051897',
 'last_fork_height': 505504,
 'latest_url': 'https://api.blockcypher.com/v1/btc/main/blocks/0000000000000000004e6a1ac1a65bfa801ad6b66d1641f2922311a410e176d1',
 'low_fee_per_kb': 200801,
 'medium_fee_per_kb': 200801,
 'name': 'BTC.main',
 'peer_count': 994,
 'previous_hash': '0000000000000000002bfae8c31731a572ce468c92957ada699e6ce69bf25bba',
 'previous_url': 'https://api.blockcypher.com/v1/btc/main/blocks/0000000000000000002bfae8c31731a572ce468c92957ada699e6ce69bf25bba',
 'time': '2018-02-02T09:35:58.567625786Z',
 'unconfirmed_count': 13622}

Summary

๐Ÿ’š easy to use
๐Ÿ’š no additional services to maintain
๐Ÿ’ฉ there are always some rate limits and paid plans with tokens
๐Ÿ’ฉ our tool will have to rely on some 3rd party service
๐Ÿ’ฉ a small number of supported networks

Solution 2

Clove user will have to have running nodes for every network that he is going to use for atomic swap. Then Clove can communicate with those nodes via RPC commands.

Summary

๐Ÿ’š good support for most networks because most clients have RPC interface
๐Ÿ’š you don't have to rely on 3rd party services
๐Ÿ’š with RPC we can use commands like fundrawtransaction or signrawtransaction to get things done quickly
๐Ÿ’ฉ a user will have install, configure and run additional software on his system
๐Ÿ’ฉ if you want to use 5 networks for atomic swaps you will need 5 nodes running on your machine
๐Ÿ’ฉ additional setup is needed in Clove to configure access to every node via RPC (port, user, password)

Solution 3

Build our public API and provide needed data from other networks by running a node for each network or getting data from other sources (like blockcypher.com) and cache them. Clove will have hardcoded address for our API.

Summary

๐Ÿ’š a user won't need to run nodes on his machine
๐Ÿ’š a large number of supported networks
๐Ÿ’ฉ we will have to maintain a new service
๐Ÿ’ฉ a user will have to rely on 3rd party service

Implement get_new_address method.

Usage example:

>> from clove import Clove
>> ltc_network = Clove('LTC')
>> ltc_network.get_new_address()
>> 'TsfWDVTAcsLaHUhHnLLKkGnZuJz2vkmM6Vr'

Fix communication for bitcoin based chains

  • publishing transaction to Litecoin network breaks with msg_reject(messsage=b'version', ccode=b'\x11', reason=b'Version must be 70002 or greater'). This value is set in version.h file.
  • params.MESSAGE_START is not updated when publishing transaction

Create signed atomic swap transaction object ready to be published

>> my_address = 'mg9sDLhfByfAWFo4zq3JZ7nsLfsN59XPue'
>> bob_btc_address = 'n31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG'
>> outpoints = [
    {
        'txid':'fdb89b980168f04cd52f6044d210a3bc37788ea26133bd74deabfa0272e06d29',
        'vout': 2,
        'value': 0.02,
        'scriptPubkey': 'g617578ac49adb77442fdbb454812bca43f324c9931d93',
    },
    {
        'txid':'abf1a090b046001f31cfacdc1db064eeb465863698c13a7a7b1f5acdf234804a',
        'vout': 0,
        'value': 0.05,
        'scriptPubkey': 'a91432d272ce8a9b482b363408a0b1dd28123d59c63387',
    },
]
>> btc_swap = btc_network.initiate_atomic_swap(sender_address=my_address, recipient_address=bob_btc_address, value=1, outpoints=outpoints, private_key='xxx')
>> btc_swap.sign(private_key, passphrase)

Publish transaction to at least three nodes

Somehow, even if everything went accordingly with expectations, transaction isn't broadcasted to the net. For now we say that transaction is published, if communication was successful with only one node. But because of this inreliability in broadcasting, we decided to rise up our broadcasting acceptance criteria. We want to publish transaction to at least three nodes, to have more certainty that transaction is broadcasted in a bloackchain. This is obviously not giving us 100% certainty, but hopefully it will improve our successful broadcasting statistics.

Publish cannot be done more than once. (Checked whilst coding)

Add ability to participate in a contract

>> tx = '0100000001b88ae2db0538ea2470b9b8f9cf80dbc5de9e90f1beeb70de6c971a8bd866cd6e010000006b483045022100fbf61a7cbc7e70de267eb8c9c99923965ed41cf63865dfc5db3848f9d819de92022069da87b34e812b2c03af6e603c4d8e17990094adc931920820e7ecd5f25aec49012103142762372a0f6f2b4718cdee32fa1a3cc2465d3379312e8875ee5f9193158177ffffffff02801d2c04000000006363a82031e09f0520d6029bd7f764e75e3dcef48833c5b5b279df16efc4d4a7b1b25cfd8876a9143f8870a5633e4fdac612fba47525fef082bbe961670a31353138323534353534b17576a914812ff3e5afea281eb3dd7fce9b077e4ec6fba08b6888acb2a88700000000001976a914812ff3e5afea281eb3dd7fce9b077e4ec6fba08b88ac00000000'
>> contract = btc_network.audit_contract(tx)
>> bob_ltc_address = 'Tsh9c9aytRaDcbLLxDRcQDRx66aXATh28R3'
>> alice_ltc_address = 'TsfWDVTAcsLaHUhHnLLKkGnZuJz2vkmM6Vr'
>> ltc_swap_tx = contract.participate(network='LTC', sender_address=bob_ltc_address, recipient_address=alice_ltc_address, value=4)

Calculate fee without signing transaction first

For API we have to deliver unsigned transaction with the correct fee so we have to estimate how does the transaction size will change after signing.

| UTXO | unsigned | signed | diff |
+------+----------+--------+------+
|    1 |      117 |    224 | +107 |
|    2 |      158 |    372 | +214 |
|    3 |      199 |    519 | +320 |

+110 bytes per utxo should be a safe value.

Create method that will return a smart contract for atomic swap

https://lamden.phacility.com/w/atomic_swap/bitcoin-based_atomic_swaps/

Bitcoin script language - https://en.bitcoin.it/wiki/Script

Usage example:

>> from clove import Clove
>> btc_network = Clove('BTC')
>> bob_btc_address = 'n31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG'
>> btc_swap = btc_network.initiate_atomic_swap(value=1, recipient_address=bob_btc_address)

# Swap will be an object or namedtuple

>> btc_swap.__dict__
>> {
    'contract': '63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac',
    'contract_address': '2MwQAMPeRGdCzFzPy7DmCnQudDVGNBFJK8S',
    'contract_transaction': '010000000267864c7145e43c84d13b514518cfdc7ca5cf2b04764ed2672caa9c8f6338a3e3010000006b483045022100901602e523f25e9659951d186eec7e8b9df9d194e8013fb6d7a05e4eafdbb61602207b66e0179a42c54d4fcfca2b1ccd89d56253cc83724593187713f6befb37866201210288ef714849ce7735b64ed886d056b80d0a384ca299090f684820d31e7682825afeffffff3ac58ce49bcef3d047ea80281659a78cd7ef8537ca2bfce336abdce41450d2d7000000006b483045022100bd1246fc18d26a9cc85c14fb60655da2f2e845af906504b8ba3acbb1b0ebf08202201ec2cd5a0c94e9e6b971ec3198be0ff57e91115342cd98ccece98d8b18294d86012103406e35c37b3b85481db7b7f7807315720dd6486c25e4f3af93d5d5f21e743881feffffff0248957e01000000001976a914c1925e7398d325820bba18726c387e9d80047ef588ac00e1f5050000000017a9142d913627b881255c417787cc255ccad9a33ce48d8700000000',
    'contract_transaction_addres': '346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88',
    'locktime': datetime(2018, 1, 19, 15, 57, 22, 524529),
    'recipient_address': 'n31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG',
    'refund_transaction': '000000000188fee037e8275f7d1e8686886a12131933f481b48902859791d6f1df01496f3401000000bf4830450221009344b17316054eae5d293b34683177fa5e7c7ba9b0001ebb2b3deca83bef552e022067088b7342bed0155b2ccef69d97cd293faa687f589d2a351aa6e154953c0c65012103a3a9f2c0492a40b134363e82959fa6132b86e0969e0b25109beb53b1debc4324004c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac0000000001e7dff505000000001976a914f5261c9e58aaa9461923c3f78f8f12f0eec22ed388acd728bd59',
    'refund_transaction_address': '45c7c175f333981508229f6fa637410fbbf4f086b657035c07adda6a49207e03',
    'secret': '3e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16',
    'secret_hash': '29c36b8dd380e0426bdc1d834e74a630bfd5d111',
    'value': 1,
    'value_text': '1 BTC',
}

>> bc_swap.publish()

Add 'message_start' and 'base58_prefixes' fields for each network class

Context:
It appeared that python-bitcoinlib is quite limited in the meaning of supporting different currency networks than Bitcoin, Bitcoin Testnet and Regtest. Especially this module is very problematic, because of its inflexibility.
Solution:
Together with @trojkat and @pafff. we agreed that it'd be best, if we apply changes to the python-bitcoinlib. Either we'll create a PR and contact with the repo owner to merge it, or (if first option will be taking too long) we'll fork the repo and apply changes there.
What is needed for our Clove codebase:
For each netwok class, we need to add fields: message_start and base58_prefixes - obviously these fields should be filled with appropriate information.

Improve getting nodes from seed

  • set timeout for connecting with a seed, as some of them are irresponsive
  • instead of eager collecting nodes from all the seeds, make lazy nodes collecting

Audit contract

Add ability to check the data in a contract from given transaction.

>> tx = '01000000013d82ce9d805205c7dca7eacec16ed4b2a7cb59007175ee7e5e58f489373ccf6b100000006a4730440220400c340543bf05654bd39df166743863115c73d2c67b2f128ce0ac355870f310022041a71977ca015e43af4081cb8ee2a4f88b6ba5f0ed50cf03f9c32ee9eea3a436012103142762372a0f6f2b4718cdee32fa1a3cc2465d3379312e8875ee5f9193158177ffffffff02e8030000000000006363a820cbb4e0a093a902f1bd609de03f3de51358033ee1ba38fc2ffc84ead7de912fdb8876a9143f8870a5633e4fdac612fba47525fef082bbe961670a31353138303937323731b17576a914812ff3e5afea281eb3dd7fce9b077e4ec6fba08b6888ac18367400000000001976a914812ff3e5afea281eb3dd7fce9b077e4ec6fba08b88ac00000000'
>> contract = btc_network.audit_contract(tx)
>> contract.show_details()
{
    'locktime': datetime.datetime(2018, 2, 8, 14, 41, 11),
    'recipient_address': 'mmJtKA92Mxqfi3XdyGReza69GjhkwAcBN1',
    'refund_address': 'msJ2ucZ2NDhpVzsiNE5mGUFzqFDggjBVTM',
    'secret_hash': 'cbb4e0a093a902f1bd609de03f3de51358033ee1ba38fc2ffc84ead7de912fdb',
    'transaction_hash': '2463bf2af63ce592f0b8dff8c22e8506edc004882a851edb45d3ddb0c5b38a49',
    'value': 1e-05,
    'value_text': '0.00001000 BTC'
}

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.