blockr

package module
v0.0.0-...-fcd7b08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2016 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Build Status GoDoc GitHub license

Blockr

Overview

This is a library to send transactions and gether unspent transaction outputs(UTXO) by blockr web API.

Requirements

This requires

  • git
  • go 1.3+

Installation

 $ go get github.com/bitgoin/blockr

Example

(This example omits error handlings for simplicity.)


import "github.com/bitgoin/blockr"

func main(){
	//prepare private key
 	txKey, err := address.FromWIF("some wif", address.BitcoinTest)

    //make service struct
	blk := Service{IsTestNet: true}

    //get utxos.
	txs, err := blk.GetUTXO(adr)

    //convert to utxo which can be used in the tx package.
	utxo, err := ToUTXO(txs, txKey)

    //prepare send info.
	send := []*tx.Send{
		&tx.Send{
			Addr:   "n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi",
			Amount: 0.01 * tx.Unit,
		},
		&tx.Send{
			Addr:   txKey.Publickey.Address(),
			Amount: 0,
		},
	}

    //create tx.
 	tx, err := tx.NewP2PK(0.0001*tx.Unit, utxo, 0, send...)

	//send tx.
	txhash, err = blk.SendTX(tx)
}

Contribution

Improvements to the codebase and pull requests are encouraged.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToUTXO

func ToUTXO(utxos []Unspent, privs *address.PrivateKey) (tx.UTXOs, error)

ToUTXO returns utxo in transaction package.

Types

type Service

type Service struct {
	IsTestNet bool
}

Service is a service using Blockr.io.

func (*Service) GetUTXO

func (b *Service) GetUTXO(addr string) ([]Unspent, error)

GetUTXO gets unspent transaction outputs by using Blockr.io.

func (*Service) SendTX

func (b *Service) SendTX(tra *tx.Tx) ([]byte, error)

SendTX send a transaction using Blockr.io.

type Unspent

type Unspent struct {
	Tx            string
	Amount        string
	N             int
	Confirmations int
	Script        string
}

Unspent represents an available transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL