Coder Social home page Coder Social logo

bitcoin-s's Introduction

#Bitcoin-S

Bitcoin-S is an implementation of the Bitcoin protocol in the Scala programming language.

##Prerequisites:

##Getting Started

Import/build the project using your preferred IDE.

We can start a bitcoin server in a Scala console by first importing the serverInitiation file and creating a instance of the ServerInitiation class.

scala> import org.scalacoin.protocol.server.ServerInitiation
import org.scalacoin.protocol.server.ServerInitiation

scala> val testNet = new ServerInitiation("bitcoind -testnet")
testNet: org.scalacoin.protocol.server.ServerInitiation = org.scalacoin.protocol.server.ServerInitiation@13ad926

##RPCs

For a complete list of RPCs for bitcoin and their descriptions, refer to https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs.

##Demonstration

Bitcoin-S has a RPC client built in. Bitcoin uses a separate program for RPCs. Starting a server uses bitcoind, RPCs use bitcoin-cli.

In a Scala console, import the file and create a new ScalaRPCClient instance. The sendCommand method will take official bitcoin RPCs and return their result. In this example, we create an RPC tool for the bitcoin test network and get the block count.

scala> import org.scalacoin.rpc.ScalaRPCClient
import org.scalacoin.rpc.ScalaRPCClient

scala> val testNet = new ScalaRPCClient("bitcoin-cli","-testnet")
testNet: org.scalacoin.rpc.ScalaRPCClient = org.scalacoin.rpc.ScalaRPCClient@106ca0dc

scala> testNet.sendCommand("getblockcount")
res8: String = "651604"

We've also predefined some RPCS to return parsed JSON values to easily interact with the data objects:

getBlockCount
getBestBlockHash
getBlockChainInfo
getMiningInfo
getNetworkInfo
getMemPoolInfo
getPeerInfo
getTxOutSetInfo
getWalletInfo
getDifficulty
getNewAddress
getRawChangeAddress
getBalance

To demonstrate since it's a small object, let's get the memory pool info. Returning MemPoolInfo using sendCommand will return the value as a string. We can also use our getMemPoolInfo RPC to return it as JSON values, which we can be used to handle the metadata inside the JSON objects:

scala> testNet.sendCommand("getmempoolinfo")
res10: String =
"{
    "size" : 2,
    "bytes" : 475
}
"

scala> testNet.getMemPoolInfo
res11: org.scalacoin.protocol.blockchain.MemPoolInfo = MemPoolInfoImpl(2,475)

scala> testNet.getMemPoolInfo.size
res12: Int = 2

scala> testNet.getMemPoolInfo.bytes
res13: Int = 475

scala> testNet.stop
res14: String = "Bitcoin server stopping"

bitcoin-s's People

Contributors

christewart avatar tommccabe avatar

Watchers

 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.