Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yzernik/bitcoin-scodec
Library for encoding Bitcoin network protocol messages in Scala.
https://github.com/yzernik/bitcoin-scodec
Last synced: 28 days ago
JSON representation
Library for encoding Bitcoin network protocol messages in Scala.
- Host: GitHub
- URL: https://github.com/yzernik/bitcoin-scodec
- Owner: yzernik
- License: mit
- Created: 2014-08-30T09:26:10.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T07:50:36.000Z (about 5 years ago)
- Last Synced: 2023-03-24T19:14:35.455Z (over 1 year ago)
- Language: Scala
- Homepage:
- Size: 351 KB
- Stars: 21
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bitcoin-scodec
[![Build Status](https://travis-ci.org/yzernik/bitcoin-scodec.svg?branch=master)](https://travis-ci.org/yzernik/bitcoin-scodec) [![Coverage Status](https://img.shields.io/coveralls/yzernik/bitcoin-scodec.svg)](https://coveralls.io/r/yzernik/bitcoin-scodec?branch=master)
Library for encoding Bitcoin [network protocol](https://en.bitcoin.it/wiki/Protocol_Specification) in Scala using [scodec](https://github.com/scodec/scodec).
### How to use
Add the following to your build.sbt:
```
libraryDependencies += "io.github.yzernik" %% "bitcoin-scodec" % "0.3.0"
```with the following resolver
``` scala
resolvers += "yzernik repo" at "http://dl.bintray.com/yzernik/maven/"
```### Encode a Bitcoin message
create a message codec
```
scala> import io.github.yzernik.bitcoinscodec.structures.{Message, Network}scala> val codec = Message.codec(Network.MainnetParams) // on the main network
```encode a ping message
```
scala> import io.github.yzernik.bitcoinscodec.messages._scala> val ping = Ping.generate
ping: io.github.yzernik.bitcoinscodec.messages.Ping = Ping(UInt64(0xd60c4f7719060e2e))scala> codec.encode(ping)
res7: scodec.Attempt[scodec.bits.BitVector] = Successful(BitVector(256 bits, 0xf9beb4d970696e670000000000000000080000003c0a64b42e0e0619774f0cd6))
```decode a pong message
```
scala> import scodec.bits._scala> val bytes = hex"0xf9beb4d9706f6e670000000000000000080000003c0a64b42e0e0619774f0cd6"
bytes: scodec.bits.ByteVector = ByteVector(32 bytes, 0xf9beb4d9706f6e670000000000000000080000003c0a64b42e0e0619774f0cd6)scala> codec.decode(bytes.toBitVector)
res1: scodec.Attempt[scodec.DecodeResult[io.github.yzernik.bitcoinscodec.structures.Message]] = Successful(DecodeResult(Pong(UInt64(0xd60c4f7719060e2e)),BitVector(empty)))
```