• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Blockchain

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    For sh*** and giggles just downloaded the latest Bitcoin Git repository and successfully compiled up
    on Ubuntu (Windows Subsystem For Linux). Pretty straight forward to do if u have Linux/C++ knowledge, takes about 30 mins.

    'aving a first browse through the source now ...
    All C++/.h, std containers etc. ..usual type of stuff if you've done C++/std on Linux coding, looks nice'n'clean ...

    Incredible that a free C++/UNIX project has created so much 'wealth' in such a short space of time !

    src/amount.h
    // Copyright (c) 2009-2010 Satoshi Nakamoto
    // Copyright (c) 2009-2016 The Bitcoin Core developers

    /** Amount in satoshis (Can be negative) */
    typedef int64_t CAmount;

    static const CAmount COIN = 100000000;
    static const CAmount CENT = 1000000;

    static const CAmount MAX_MONEY = 21000000 * COIN;



    src/utilmoneystr.cpp:
    // Copyright (c) 2009-2010 Satoshi Nakamoto
    // Copyright (c) 2009-2016 The Bitcoin Core developers

    std::string FormatMoney(const CAmount& n)
    {
    // Note: not using straight sprintf here because we do NOT want
    // localized number formatting.
    int64_t n_abs = (n > 0 ? n : -n);
    int64_t quotient = n_abs/COIN;
    int64_t remainder = n_abs%COIN;
    std::string str = strprintf("%d.%08d", quotient, remainder);

    // Right-trim excess zeros before the decimal point:
    int nTrim = 0;
    for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i)
    ++nTrim;
    if (nTrim)
    str.erase(str.size()-nTrim, nTrim);

    if (n < 0)
    str.insert((unsigned int)0, 1, '-');
    return str;
    }



    src/wallet/wallet.cpp
    // Copyright (c) 2009-2010 Satoshi Nakamoto
    // Copyright (c) 2009-2016 The Bitcoin Core developers

    bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
    {
    LOCK(cs_wallet);

    CWalletDB walletdb(*dbw, "r+", fFlushOnClose);

    uint256 hash = wtxIn.GetHash();

    Comment


      #12
      Originally posted by Lance View Post
      The work under the bonnet is heavy-duty cryptographics.
      Tis, however on first look the lowest level Bitcoin crypto is probably 'inspired' rather than 'created from scratch'.

      2005 http://www.ouah.org/ogay/sha2/
      sha2.c
      uint64 sha512_h0[8] =
      {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
      0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
      0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
      0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};


      2012 C++ sha512 function :: zedwood.com
      sha512.cpp

      void SHA512::init()
      {
      m_h[0] = 0x6a09e667f3bcc908ULL;
      m_h[1] = 0xbb67ae8584caa73bULL;
      m_h[2] = 0x3c6ef372fe94f82bULL;
      m_h[3] = 0xa54ff53a5f1d36f1ULL;
      m_h[4] = 0x510e527fade682d1ULL;
      m_h[5] = 0x9b05688c2b3e6c1fULL;
      m_h[6] = 0x1f83d9abfb41bd6bULL;
      m_h[7] = 0x5be0cd19137e2179ULL;
      m_len = 0;
      m_tot_len = 0;
      }


      2017 Bitcoin
      bitcoin-master/src/crypto/sha512.cpp
      // Copyright (c) 2014 The Bitcoin Core developers

      void inline Initialize(uint64_t* s)
      {
      s[0] = 0x6a09e667f3bcc908ull;
      s[1] = 0xbb67ae8584caa73bull;
      s[2] = 0x3c6ef372fe94f82bull;
      s[3] = 0xa54ff53a5f1d36f1ull;
      s[4] = 0x510e527fade682d1ull;
      s[5] = 0x9b05688c2b3e6c1full;
      s[6] = 0x1f83d9abfb41bd6bull;
      s[7] = 0x5be0cd19137e2179ull;
      }

      Comment


        #13
        I've started reading up on Ethereum and 'smart contracts'. From what I've learnt it's a platform for a big virtual 'computer' that can run code but has no specific hardware, virtual server and centralized anything.

        I find smart contracts and 'crypto law' interesting as it opens the door for people to have peer-to-peer legal agreements (eg music royalty payments direct between artists and fans when downloading/streaming music) that are recorded on the blockchain. At the moment it would involve ether (ethereum currency) which if bitcoin is anything to go by is clunky, not instant and a PITA to set up, so don't see blockchain disrupting traditional music distribution and royalty payment systems soon.

        But if it became possible to link a paypal account or some similar quick and easy traditional payment method to peer-to-peer blockchain smart contracts (think buying selling cars, houses etc. without any Ebay/Amazon type middlemen) it could get very interesting indeed.

        I'm not that techy so have a lot more to understand but I like the potential of ethereum type 'apps' and contracts and peer-to-peer transactions.
        "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

        Comment


          #14
          Good primer on ethereum here:

          https://www.coindesk.com/information/what-is-ethereum/

          The 'World Computer'

          In short, ethereum wants to be a 'World Computer' that would decentralize – and some would argue, democratize – the existing client-server model.

          With ethereum, servers and clouds are replaced by thousands of so-called "nodes" run by volunteers from across the globe (thus forming a "world computer").

          The vision is that ethereum would enable this same functionality to people anywhere around the world, enabling them to compete to offer services on top of this infrastructure.
          "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

          Comment


            #15
            /*
            Simple blockchain using a CUKC - Contractor UK coin. Just like parts of Ethereum, written in the 'C like' Go language
            Code taken from Aug 2017 Ivan Kuznetsov article at https://jeiwan.cc/posts/building-blo...-in-go-part-1/
            To easily test copy'n'paste everything into the top part of the yellow 'Try Go' box at https://golang.org and press 'Run'
            */

            package main

            import (
            "bytes"
            "crypto/sha256"
            "strconv"
            "time"
            )

            import (
            "fmt"
            )

            type Block struct {
            Timestamp int64
            Data []byte
            PrevBlockHash []byte
            Hash []byte
            }

            type Blockchain struct {
            blocks []*Block
            }

            func (b *Block) SetHash() {
            timestamp := []byte(strconv.FormatInt(b.Timestamp, 10))
            headers := bytes.Join([][]byte{b.PrevBlockHash, b.Data, timestamp}, []byte{})
            hash := sha256.Sum256(headers)
            b.Hash = hash[:]
            }

            func NewBlock(data string, prevBlockHash []byte) *Block {
            block := &Block{time.Now().Unix(), []byte(data), prevBlockHash, []byte{}}
            block.SetHash()
            return block
            }

            func NewGenesisBlock() *Block {
            return NewBlock("Genesis Block", []byte{})
            }

            func (bc *Blockchain) AddBlock(data string) {
            prevBlock := bc.blocks[len(bc.blocks)-1]
            newBlock := NewBlock(data, prevBlock.Hash)
            bc.blocks = append(bc.blocks, newBlock)
            }

            func NewBlockchain() *Blockchain {
            return &Blockchain{[]*Block{NewGenesisBlock()}}
            }

            func main() {
            bc := NewBlockchain()
            bc.AddBlock("Send 1 CUKC to Sally")
            bc.AddBlock("Send 2 more CUKC to Mike")
            for _, block := range bc.blocks {
            fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
            fmt.Printf("Data: %s\n", block.Data)
            fmt.Printf("Hash: %x\n", block.Hash)
            fmt.Println()
            }
            }
            Last edited by SunnyInHades; 10 November 2017, 12:52.

            Comment


              #16
              Originally posted by SunnyInHades View Post
              /*
              Simple blockchain using a CUKC - Contractor UK coin. Just like parts of Ethereum, written in the 'C like' Go language
              Code taken from Aug 2017 Ivan Kuznetsov article at https://jeiwan.cc/posts/building-blo...-in-go-part-1/
              To easily test copy'n'paste everything into the top part of the yellow 'Try Go' box at https://golang.org and press 'Run'
              */

              package main

              import (
              "bytes"
              "crypto/sha256"
              "strconv"
              "time"
              )

              import (
              "fmt"
              )

              type Block struct {
              Timestamp int64
              Data []byte
              PrevBlockHash []byte
              Hash []byte
              }

              type Blockchain struct {
              blocks []*Block
              }

              func (b *Block) SetHash() {
              timestamp := []byte(strconv.FormatInt(b.Timestamp, 10))
              headers := bytes.Join([][]byte{b.PrevBlockHash, b.Data, timestamp}, []byte{})
              hash := sha256.Sum256(headers)
              b.Hash = hash[:]
              }

              func NewBlock(data string, prevBlockHash []byte) *Block {
              block := &Block{time.Now().Unix(), []byte(data), prevBlockHash, []byte{}}
              block.SetHash()
              return block
              }

              func NewGenesisBlock() *Block {
              return NewBlock("Genesis Block", []byte{})
              }

              func (bc *Blockchain) AddBlock(data string) {
              prevBlock := bc.blocks[len(bc.blocks)-1]
              newBlock := NewBlock(data, prevBlock.Hash)
              bc.blocks = append(bc.blocks, newBlock)
              }

              func NewBlockchain() *Blockchain {
              return &Blockchain{[]*Block{NewGenesisBlock()}}
              }

              func main() {
              bc := NewBlockchain()
              bc.AddBlock("Send 1 CUKC to Sally")
              bc.AddBlock("Send 2 more CUKC to Mike")
              for _, block := range bc.blocks {
              fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
              fmt.Printf("Data: %s\n", block.Data)
              fmt.Printf("Hash: %x\n", block.Hash)
              fmt.Println()
              }
              }
              When is the ICO?
              "Is someone you don't like allowed to say something you don't like? If that is the case then we have free speech."- Elon Musk

              Comment

              Working...
              X