gIOTA: The IOTA Go API Library
Switch branches/tags
Nothing to show
Clone or download
knarz Merge pull request #76 from shimonp21/bugfix-broadcast-and-store
adds call to StoreTransactions in SendTrytes/Promote methods
Latest commit e34a409 Aug 23, 2018
Permalink
Failed to load latest commit information.
cl added avx pow Apr 30, 2017
examples/getinputs Import the right package in examples Jan 13, 2018
.travis.yml updates .travis.yml to use more recent golang versions Jun 25, 2018
LICENSE refresh,added sig Mar 11, 2017
README.md Corrected links. Added GoReportCard. Formatting and spelling changes. Jun 26, 2018
api.go Add JRE Version to NodeInfo response Feb 25, 2018
api_test.go Add Promote function and set attach timestamps Feb 15, 2018
bigint.go Comment Spacing, Tests, and Formatting Jan 12, 2018
bundle.go s/getValidHash/GetValidHash Jun 15, 2018
bundle_test.go Fixed bug in TestBundle Jan 25, 2018
constants.go Comment Spacing, Tests, and Formatting Jan 12, 2018
curl.go Comment Spacing, Tests, and Formatting Jan 12, 2018
curl_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
curl_transform.go Fixes PoW C not being able to be compiled on ARM Feb 25, 2018
kerl.go Fix keccak package import Feb 23, 2018
kerl_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
pow_avx.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_avx_test.go remove LDFLAGS -mavx and fix build constraints Jun 25, 2018
pow_c.go Ignore c compiler warnings when building pow_c.go Jul 29, 2018
pow_c128.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_c128_test.go Add of Pow_C128 - 128 bit Pow calc using standard C instructions for … Mar 5, 2018
pow_cARM_ARM64.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_cARM_ARM64_test.go Added ARM64 NEON accelerated POW Mar 14, 2018
pow_c_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
pow_cl.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_cl_kernel.go gometalinter Jun 14, 2017
pow_cl_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
pow_go.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_go_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
pow_sse.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
pow_sse_test.go Fix output of pow_sse_test Feb 11, 2018
sign.go Comment Spacing, Tests, and Formatting Jan 12, 2018
sign_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
transaction.go Changed transactionTrinarySize from private to puplic Jul 6, 2018
transaction_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
transfer.go BUGFIX - Added call to StoreTransactions Aug 21, 2018
transfer_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018
trinary.go Fixed bug in TestBundle Jan 25, 2018
trinary_test.go Comment Spacing, Tests, and Formatting Jan 12, 2018

README.md

Build Status GoDoc GitHub license Go Report Card

gIOTA

Client library for the IOTA reference implementation (IRI).

This library is still in flux and there maybe breaking changes.

Consider to use a dependency tool to use vendoring, e.g. godep, glide or govendor.

Refer to godoc for details.

Install

You will need C compiler for linux to compile PoW routine in C.

$ go get -u github.com/iotaledger/giota

You will need C compiler and OpenCL environment (hardware and software) to compile PoW routine for GPU and need to add opencl tag when you build.

$ go build -tags=gpu

Examples

import "github.com/iotaledger/giota"

//Trits
tritsFrom:=[]int8{1,-1,1,0,1,1,0,-1,0}
trits,err:=giota.ToTrits(tritsFrom)

//Trytes
trytes:=trits.Trytes()
trytesFrom:="ABCDEAAC9ACB9PO..."
trytes2,err:=giota.ToTrytes(trytesFrom)

//Hash
hash:=trytes.Hash()

//API
api := giota.NewAPI("http://localhost:14265", nil)
resp, err := api.FindTransactions([]Trytes{"DEXRPL...SJRU"})

///Address
index:=0
security:=2
adr,err:=giota.NewAddress(trytes,index,security) //without checksum.
adrWithChecksum := adr.WithChecksum() //adrWithChecksum is trytes type.

//transaction
tx,err:=giota.NewTransaction(trytes)
mwm := 14
if tx.HasValidNonce(mwm){...}
trytes2:=tx.trytes()

//create signature
key := giota.NewKey(seed, index, security)
norm := bundleHash.Normalize()
sign := giota.Sign(norm[:27], key[:6561/3])

//validate signature
if giota.ValidateSig(adr, []giota.Trytes{sign}, bundleHash) {...}

//send
trs := []giota.Transfer{
	giota.Transfer{
		Address: "KTXF...QTIWOWTY",
		Value:   20,
		Tag: "MOUDAMEPO",
	},
}
_, pow := giota.GetBestPoW()
bdl, err = giota.Send(api, seed, security, trs, mwm, pow)


// promote transaction
trs := []giota.Transfer{
	giota.Transfer{
		Address: "999...9999999",
		Value:   0,
		Tag: "PROMOTESPAM",
	},
}
tail := []giota.Trytes("NLN...TY99999")
_, pow := giota.GetBestPoW()
bdl, err = giota.Promote(api, tail, giota.Depth, trs, mwm, pow)

PoW (Proof of Work) Benchmarking

You can benchmark PoWs (by C,Go,SSE) by

$ go test -v -run Pow

or if you want to add OpenCL PoW,

$ go test -tags=gpu -v -run Pow

then it outputs like:

$ go test -tags=gpu -v -run Pow
=== RUN   TestPowC
--- PASS: TestPowC (15.93s)
	pow_c_test.go:50: 1550 kH/sec on C PoW
=== RUN   TestPowCL
--- PASS: TestPowCL (17.45s)
	pow_cl_test.go:49: 332 kH/sec on GPU PoW
=== RUN   TestPowGo
--- PASS: TestPowGo (21.21s)
	pow_go_test.go:50: 1164 kH/sec on Go PoW
=== RUN   TestPowSSE
--- PASS: TestPowSSE (13.41s)
	pow_sse_test.go:52: 2292 kH/sec on SSE PoW

Note that in travis CI the result is:

=== RUN   TestPowSSE
--- PASS: TestPowSSE (2.73s)
	pow_sse_test.go:52: 12902 kH/sec on SSE PoW
=== RUN   TestPowSSE1
--- PASS: TestPowSSE1 (16.19s)
	pow_sse_test.go:59: 1900 kH/sec on SSE PoW
=== RUN   TestPowSSE32
--- PASS: TestPowSSE32 (1.36s)
	pow_sse_test.go:67: 16117 kH/sec on SSE PoW
=== RUN   TestPowSSE64
--- PASS: TestPowSSE64 (0.73s)
	pow_sse_test.go:75: 20226 kH/sec on SSE PoW

It gets over 20MH/s for 64 threads using SSE2.

Now IOTA uses Min Weight Magnitude = 15, which means 3^15≒14M Hashes are needed to finish PoW in average. So it takes just 14/20 < 0.7sec for 1 tx to do PoW.

TODO

  • Multisig
  • More tests :(

Released under the MIT License.