Code Monkey home page Code Monkey logo

go-bitshares's Introduction

go-bitshares

A Bitshares API consuming a websocket connection to an active full node or a RPC connection to your cli_wallet. Look for several examples in examples and tests folder. This is work in progress. To mitigate breaking changes, please use tagged branches. New tagged branches will be created for breaking changes. No additional cgo dependencies for transaction signing required. Use it at your own risk.

install

go get -u github.com/denkhaus/go-bitshares

Install dev-dependencies with

make init

This API uses ffjson. If you change types or operations you have to regenerate the required static MarshalJSON and UnmarshalJSON functions for the new/changed code.

make generate

If you encounter any errors, try:

make generate_new

to generate ffjson helpers from scratch.

generate operation samples

To generate op samples for testing, go to gen package. Generated operation samples get injected automatically while running operation tests.

testing

To test this stuff I use a combined docker based MainNet/TestNet wallet, you can find here. Operations testing uses generated real blockchain sample code by gen package. To test run:

make test_operations
make test_api

or a long running block (deserialize/serialize/compare) range test.

make test_blocks

code

wsFullApiUrl := "wss://bitshares.openledger.info/ws"

api := bitshares.NewWebsocketAPI(wsFullApiUrl)
if err := api.Connect(); err != nil {
	log.Fatal(err)
}

api.OnError(func(err error) {
	log.Fatal(err)
})

UserID   := types.NewAccountID("1.2.253")
AssetBTS := types.NewAssetID("1.3.0")

res, api.GetAccountBalances(UserID, AssetBTS)
if err != nil {
	log.Fatal(err)
}

log.Printf("balances: %v", res)

If you need wallet functions, use:

rpcApiUrl    := "http://localhost:8095" 
api := bitshares.NewWalletAPI(rpcApiUrl)

if err := api.Connect(); err != nil{
	log.Fatal(err)
}

...

For a long application lifecycle, you can use an API instance with latency tester that connects to the most reliable node. Note: Because the tester takes time to unleash its magic, use the above-mentioned constructor for quick in and out.

wsFullApiUrl := "wss://bitshares.openledger.info/ws"

//wsFullApiUrl serves as "quick startup" fallback endpoint here, 
//until the latency tester provides the first results.

api, err := bitshares.NewWithAutoEndpoint(wsFullApiUrl)
if err != nil {
	log.Fatal(err)
}

if err := api.Connect(); err != nil {
	log.Fatal(err)
}

api.OnError(func(err error) {
	log.Fatal(err)
})

...

implemented and tested (serialize/unserialize) operations

  • OperationTypeTransfer OperationType
  • OperationTypeLimitOrderCreate
  • OperationTypeLimitOrderCancel
  • OperationTypeCallOrderUpdate
  • OperationTypeFillOrder (virtual)
  • OperationTypeAccountCreate
  • OperationTypeAccountUpdate
  • OperationTypeAccountWhitelist
  • OperationTypeAccountUpgrade
  • OperationTypeAccountTransfer
  • OperationTypeAssetCreate
  • OperationTypeAssetUpdate
  • OperationTypeAssetUpdateBitasset
  • OperationTypeAssetUpdateFeedProducers
  • OperationTypeAssetIssue
  • OperationTypeAssetReserve
  • OperationTypeAssetFundFeePool
  • OperationTypeAssetSettle
  • OperationTypeAssetGlobalSettle
  • OperationTypeAssetPublishFeed
  • OperationTypeWitnessCreate
  • OperationTypeWitnessUpdate
  • OperationTypeProposalCreate
  • OperationTypeProposalUpdate
  • OperationTypeProposalDelete
  • OperationTypeWithdrawPermissionCreate
  • OperationTypeWithdrawPermissionUpdate
  • OperationTypeWithdrawPermissionClaim
  • OperationTypeWithdrawPermissionDelete
  • OperationTypeCommitteeMemberCreate
  • OperationTypeCommitteeMemberUpdate
  • OperationTypeCommitteeMemberUpdateGlobalParameters
  • OperationTypeVestingBalanceCreate
  • OperationTypeVestingBalanceWithdraw
  • OperationTypeWorkerCreate
  • OperationTypeCustom
  • OperationTypeAssert
  • OperationTypeBalanceClaim
  • OperationTypeOverrideTransfer
  • OperationTypeTransferToBlind
  • OperationTypeBlindTransfer
  • OperationTypeTransferFromBlind
  • OperationTypeAssetSettleCancel
  • OperationTypeAssetClaimFees
  • OperationTypeFBADistribute
  • OperationTypeBidColatteral
  • OperationTypeExecuteBid

todo

  • add missing operations
  • add convenience functions

Have fun and feel free to contribute needed operations and tests.

go-bitshares's People

Contributors

denkhaus avatar asuan avatar iuouiyiuty avatar saniales avatar fanyinghao avatar gitmonster avatar liandeliang avatar

Watchers

James Cloos 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.