From b5ec7827236765ec0e068ccb3f9eb680c23a7d5b Mon Sep 17 00:00:00 2001 From: Wolfgang Welz <welzwo@gmail.com> Date: Fri, 5 Jul 2019 17:44:48 +0200 Subject: [PATCH] Use iota.go --- go.mod | 2 +- go.sum | 38 ++++ packages/curl/batch_hasher.go | 11 +- packages/curl/bct_curl.go | 9 +- packages/curl/curl.go | 18 +- packages/iac/area.go | 4 +- packages/iac/iac.go | 4 +- packages/iac/olc_conversion.go | 8 +- packages/model/approvers/approvers.go | 37 ++-- packages/model/approvers/approvers_test.go | 10 +- packages/model/bundle/bundle.go | 38 ++-- packages/model/bundle/bundle_test.go | 18 +- packages/model/meta_transaction/constants.go | 4 +- .../meta_transaction/meta_transaction.go | 73 +++---- .../meta_transaction/meta_transaction_test.go | 10 +- .../transactionmetadata.go | 21 +- packages/model/value_transaction/constants.go | 4 +- .../value_transaction/value_transaction.go | 53 +++--- .../value_transaction_test.go | 4 +- packages/ternary/bc_ternary_demultiplexer.go | 4 + packages/ternary/bc_ternary_multiplexer.go | 2 + packages/ternary/conversion.go | 179 ------------------ packages/ternary/conversion_test.go | 21 -- packages/ternary/ternary.go | 105 ---------- plugins/bundleprocessor/plugin.go | 8 +- plugins/cli/plugin.go | 2 +- plugins/gossip/protocol_v1.go | 8 +- plugins/gossip/transaction_processor_test.go | 6 +- plugins/tangle/approvers.go | 17 +- plugins/tangle/bundle.go | 17 +- plugins/tangle/solidifier.go | 6 +- plugins/tangle/solidifier_test.go | 4 +- plugins/tangle/transaction.go | 17 +- plugins/tangle/transaction_metadata.go | 17 +- plugins/tipselection/tipselection.go | 6 +- plugins/webapi-gtta/plugin.go | 6 +- plugins/zeromq/plugin.go | 10 +- 37 files changed, 279 insertions(+), 522 deletions(-) delete mode 100644 packages/ternary/conversion.go delete mode 100644 packages/ternary/conversion_test.go delete mode 100644 packages/ternary/ternary.go diff --git a/go.mod b/go.mod index 5b1e2b90..98fab30b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/iotaledger/goshimmer go 1.12 require ( - github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 // indirect github.com/dgraph-io/badger v2.0.0-rc.2.0.20190610165348-a804ffa35fb9+incompatible github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect github.com/dustin/go-humanize v1.0.0 // indirect @@ -12,6 +11,7 @@ require ( github.com/go-zeromq/zmq4 v0.4.0 github.com/golang/protobuf v1.3.1 // indirect github.com/google/open-location-code/go v0.0.0-20190603181809-cf814bded323 + github.com/iotaledger/iota.go v1.0.0-beta.6 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.2.9 // indirect github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index 58add10c..9ca44d69 100644 --- a/go.sum +++ b/go.sum @@ -2,28 +2,42 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkBy github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgraph-io/badger v2.0.0-rc.2.0.20190610165348-a804ffa35fb9+incompatible h1:FE+hrPTLWIHxQzGTbjReHgpkj7+hFWC+L6b2fAxBG+I= github.com/dgraph-io/badger v2.0.0-rc.2.0.20190610165348-a804ffa35fb9+incompatible/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= +github.com/dgryski/go-farm v0.0.0-20190323231341-8198c7b169ec/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/ethereum/go-ethereum v1.8.27 h1:d+gkiLaBDk5fn3Pe/xNVaMrB/ozI+AUB2IlVBp29IrY= github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell v1.1.2 h1:Afe8cU6SECC06UmvaJ55Jr3Eh0tz/ywLjqWYqjGZp3s= github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-zeromq/zmq4 v0.4.0 h1:/TAahvAez7b6ycAyrxwN6Q36zy2OU8++uRLt6CwC74g= github.com/go-zeromq/zmq4 v0.4.0/go.mod h1:Sm+6QJXXpXzdGVlOTEvV/6SDt+koNyLZwxe7sORh7FI= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/open-location-code/go v0.0.0-20190603181809-cf814bded323 h1:s+TV4ZPsmXNvFxr9gzRTOlqf7DT862ieiOGRWA9M3oM= github.com/google/open-location-code/go v0.0.0-20190603181809-cf814bded323/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk= +github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/iotaledger/iota.go v1.0.0-beta.6 h1:KpYLldGNENbalmGDsX2Rw3kVA2Gu6z4eJIbRfuM6A1c= +github.com/iotaledger/iota.go v1.0.0-beta.6/go.mod h1:3oE7biGf+UbsMlOzUINTMXhQLEgYgEqDIYHJAst2WsA= github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU= @@ -38,6 +52,12 @@ github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -47,6 +67,7 @@ github.com/rivo/tview v0.0.0-20190609162513-b62197ade412 h1:muOFMct2jVhlSw9S3MRr github.com/rivo/tview v0.0.0-20190609162513-b62197ade412/go.mod h1:+rKjP5+h9HMwWRpAfhIkkQ9KE3m3Nz5rwn7YtUpwgqk= github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44 h1:XKCbzPvK4/BbMXoMJOkYP2ANxiAEO0HM1xn6psSbXxY= github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= @@ -55,22 +76,39 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/zeromq/goczmq v4.1.0+incompatible h1:cGVQaU6kIwwrGso0Pgbl84tzAz/h7FJ3wYQjSonjFFc= github.com/zeromq/goczmq v4.1.0+incompatible/go.mod h1:1uZybAJoSRCvZMH2rZxEwWBSmC4T7CB/xQOfChwPEzg= +go.mongodb.org/mongo-driver v1.0.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20180629035331-4cb1c02c05b0/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190611141213-3f473d35a33a h1:+KkCgOMgnKSgenxTBoiwkMqTiouMIy/3o8RLdmSbGoY= golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cjyFjutgw/Vhan2zLy/A= golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/h2non/gock.v1 v1.0.14/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/packages/curl/batch_hasher.go b/packages/curl/batch_hasher.go index 367ff8e0..b9a4059f 100644 --- a/packages/curl/batch_hasher.go +++ b/packages/curl/batch_hasher.go @@ -6,11 +6,12 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) type HashRequest struct { - input ternary.Trits - output chan ternary.Trits + input trinary.Trits + output chan trinary.Trits } type BatchHasher struct { @@ -94,7 +95,7 @@ func (this *BatchHasher) processHashes(collectedHashRequests []HashRequest) { close(hashRequest.output) } } else { - var resp = make(ternary.Trits, this.hashLength) + var resp = make(trinary.Trits, this.hashLength) curl := NewCurl(this.hashLength, this.rounds) curl.Absorb(collectedHashRequests[0].input, 0, len(collectedHashRequests[0].input)) @@ -105,10 +106,10 @@ func (this *BatchHasher) processHashes(collectedHashRequests []HashRequest) { } } -func (this *BatchHasher) Hash(trits ternary.Trits) chan ternary.Trits { +func (this *BatchHasher) Hash(trits trinary.Trits) chan trinary.Trits { hashRequest := HashRequest{ input: trits, - output: make(chan ternary.Trits, 1), + output: make(chan trinary.Trits, 1), } this.hashRequests <- hashRequest diff --git a/packages/curl/bct_curl.go b/packages/curl/bct_curl.go index 7933d3bc..9a8f95fe 100644 --- a/packages/curl/bct_curl.go +++ b/packages/curl/bct_curl.go @@ -3,7 +3,8 @@ package curl import "github.com/iotaledger/goshimmer/packages/ternary" const ( - HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFF + HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFF + NUMBER_OF_TRITS_IN_A_TRYTE = 3 ) type BCTCurl struct { @@ -18,10 +19,10 @@ func NewBCTCurl(hashLength int, numberOfRounds int) *BCTCurl { this := &BCTCurl{ hashLength: hashLength, numberOfRounds: numberOfRounds, - stateLength: ternary.NUMBER_OF_TRITS_IN_A_TRYTE * hashLength, + stateLength: NUMBER_OF_TRITS_IN_A_TRYTE * hashLength, state: ternary.BCTrits{ - Lo: make([]uint, ternary.NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), - Hi: make([]uint, ternary.NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), + Lo: make([]uint, NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), + Hi: make([]uint, NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), }, cTransform: nil, } diff --git a/packages/curl/curl.go b/packages/curl/curl.go index 9409050a..621ada16 100644 --- a/packages/curl/curl.go +++ b/packages/curl/curl.go @@ -3,16 +3,16 @@ package curl import ( "math" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) const ( HASH_LENGTH = 243 - STATE_LENGTH = ternary.NUMBER_OF_TRITS_IN_A_TRYTE * HASH_LENGTH + STATE_LENGTH = 3 * HASH_LENGTH ) var ( - TRUTH_TABLE = ternary.Trits{1, 0, -1, 2, 1, -1, 0, 2, -1, 1, 0} + TRUTH_TABLE = trinary.Trits{1, 0, -1, 2, 1, -1, 0, 2, -1, 1, 0} ) type Hash interface { @@ -25,7 +25,7 @@ type Hash interface { type Curl struct { Hash - state ternary.Trits + state trinary.Trits hashLength int rounds int } @@ -45,12 +45,12 @@ func (curl *Curl) Initialize() { curl.InitializeCurl(nil, 0, curl.rounds) } -func (curl *Curl) InitializeCurl(trits ternary.Trits, length int, rounds int) { +func (curl *Curl) InitializeCurl(trits trinary.Trits, length int, rounds int) { curl.rounds = rounds if trits != nil { curl.state = trits } else { - curl.state = make(ternary.Trits, STATE_LENGTH) + curl.state = make(trinary.Trits, STATE_LENGTH) } } @@ -58,7 +58,7 @@ func (curl *Curl) Reset() { curl.InitializeCurl(nil, 0, curl.rounds) } -func (curl *Curl) Absorb(trits ternary.Trits, offset int, length int) { +func (curl *Curl) Absorb(trits trinary.Trits, offset int, length int) { for { limit := int(math.Min(HASH_LENGTH, float64(length))) copy(curl.state, trits[offset:offset+limit]) @@ -71,7 +71,7 @@ func (curl *Curl) Absorb(trits ternary.Trits, offset int, length int) { } } -func (curl *Curl) Squeeze(resp ternary.Trits, offset int, length int) ternary.Trits { +func (curl *Curl) Squeeze(resp trinary.Trits, offset int, length int) trinary.Trits { for { limit := int(math.Min(HASH_LENGTH, float64(length))) copy(resp[offset:offset+limit], curl.state) @@ -88,7 +88,7 @@ func (curl *Curl) Squeeze(resp ternary.Trits, offset int, length int) ternary.Tr func (curl *Curl) Transform() { var index = 0 for round := 0; round < curl.rounds; round++ { - stateCopy := make(ternary.Trits, STATE_LENGTH) + stateCopy := make(trinary.Trits, STATE_LENGTH) copy(stateCopy, curl.state) for i := 0; i < STATE_LENGTH; i++ { incr := 364 diff --git a/packages/iac/area.go b/packages/iac/area.go index d30b7899..7140e553 100644 --- a/packages/iac/area.go +++ b/packages/iac/area.go @@ -4,12 +4,12 @@ import ( "math" olc "github.com/google/open-location-code/go" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) type Area struct { olc.CodeArea - IACCode ternary.Trytes + IACCode trinary.Trytes OLCCode string } diff --git a/packages/iac/iac.go b/packages/iac/iac.go index ff61d604..e1e69661 100644 --- a/packages/iac/iac.go +++ b/packages/iac/iac.go @@ -3,10 +3,10 @@ package iac import ( olc "github.com/google/open-location-code/go" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) -func Decode(trytes ternary.Trytes) (result *Area, err errors.IdentifiableError) { +func Decode(trytes trinary.Trytes) (result *Area, err errors.IdentifiableError) { if olcCode, conversionErr := OLCCodeFromTrytes(trytes); conversionErr != nil { err = conversionErr } else { diff --git a/packages/iac/olc_conversion.go b/packages/iac/olc_conversion.go index 053ea852..632280d7 100644 --- a/packages/iac/olc_conversion.go +++ b/packages/iac/olc_conversion.go @@ -2,7 +2,7 @@ package iac import ( "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) var ( @@ -31,10 +31,10 @@ func init() { IAC_TO_OLC_MAP[IAC_PADDING] = OLC_PADDING } -func TrytesFromOLCCode(code string) (result ternary.Trytes, err errors.IdentifiableError) { +func TrytesFromOLCCode(code string) (result trinary.Trytes, err errors.IdentifiableError) { for _, char := range code { if translatedChar, exists := OLC_TO_IAC_MAP[char]; exists { - result += ternary.Trytes(translatedChar) + result += trinary.Trytes(translatedChar) } else { err = ErrConversionFailed.Derive("invalid character in input") } @@ -43,7 +43,7 @@ func TrytesFromOLCCode(code string) (result ternary.Trytes, err errors.Identifia return } -func OLCCodeFromTrytes(trytes ternary.Trytes) (result string, err errors.IdentifiableError) { +func OLCCodeFromTrytes(trytes trinary.Trytes) (result string, err errors.IdentifiableError) { for _, char := range trytes { if translatedChar, exists := IAC_TO_OLC_MAP[char]; exists { result += string(translatedChar) diff --git a/packages/model/approvers/approvers.go b/packages/model/approvers/approvers.go index a733922a..4a15a05c 100644 --- a/packages/model/approvers/approvers.go +++ b/packages/model/approvers/approvers.go @@ -6,40 +6,41 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) type Approvers struct { - hash ternary.Trytes - hashes map[ternary.Trytes]bool + hash trinary.Trytes + hashes map[trinary.Trytes]bool hashesMutex sync.RWMutex modified bool } -func New(hash ternary.Trytes) *Approvers { +func New(hash trinary.Trytes) *Approvers { return &Approvers{ hash: hash, - hashes: make(map[ternary.Trytes]bool), + hashes: make(map[trinary.Trytes]bool), modified: false, } } // region public methods with locking ////////////////////////////////////////////////////////////////////////////////// -func (approvers *Approvers) Add(transactionHash ternary.Trytes) { +func (approvers *Approvers) Add(transactionHash trinary.Trytes) { approvers.hashesMutex.Lock() approvers.add(transactionHash) approvers.hashesMutex.Unlock() } -func (approvers *Approvers) Remove(approverHash ternary.Trytes) { +func (approvers *Approvers) Remove(approverHash trinary.Trytes) { approvers.hashesMutex.Lock() approvers.remove(approverHash) approvers.hashesMutex.Unlock() } -func (approvers *Approvers) GetHashes() (result []ternary.Trytes) { +func (approvers *Approvers) GetHashes() (result []trinary.Trytes) { approvers.hashesMutex.RLock() result = approvers.getHashes() approvers.hashesMutex.RUnlock() @@ -47,7 +48,7 @@ func (approvers *Approvers) GetHashes() (result []ternary.Trytes) { return } -func (approvers *Approvers) GetHash() (result ternary.Trytes) { +func (approvers *Approvers) GetHash() (result trinary.Trytes) { approvers.hashesMutex.RLock() result = approvers.hash approvers.hashesMutex.RUnlock() @@ -69,14 +70,14 @@ func (approvers *Approvers) Marshal() (result []byte) { binary.BigEndian.PutUint64(result[MARSHALED_APPROVERS_HASHES_COUNT_START:MARSHALED_APPROVERS_HASHES_COUNT_END], uint64(len(approvers.hashes))) - copy(result[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END], approvers.hash.CastToBytes()) + copy(result[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END], unsafeconvert.StringToBytes(approvers.hash)) i := 0 for hash := range approvers.hashes { var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_APPROVERS_HASH_SIZE) var HASH_END = HASH_START + MARSHALED_APPROVERS_HASH_SIZE - copy(result[HASH_START:HASH_END], hash.CastToBytes()) + copy(result[HASH_START:HASH_END], unsafeconvert.StringToBytes(hash)) i++ } @@ -101,13 +102,13 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError approvers.hashesMutex.Lock() - approvers.hash = ternary.Trytes(typeutils.BytesToString(data[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END])) - approvers.hashes = make(map[ternary.Trytes]bool, hashesCount) + approvers.hash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END])) + approvers.hashes = make(map[trinary.Trytes]bool, hashesCount) for i := uint64(0); i < hashesCount; i++ { var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_APPROVERS_HASH_SIZE) var HASH_END = HASH_START + MARSHALED_APPROVERS_HASH_SIZE - approvers.hashes[ternary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true + approvers.hashes[trinary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true } approvers.hashesMutex.Unlock() @@ -119,22 +120,22 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError // region private methods without locking ////////////////////////////////////////////////////////////////////////////// -func (approvers *Approvers) add(transactionHash ternary.Trytes) { +func (approvers *Approvers) add(transactionHash trinary.Trytes) { if _, exists := approvers.hashes[transactionHash]; !exists { approvers.hashes[transactionHash] = true approvers.modified = true } } -func (approvers *Approvers) remove(approverHash ternary.Trytes) { +func (approvers *Approvers) remove(approverHash trinary.Trytes) { if _, exists := approvers.hashes[approverHash]; exists { delete(approvers.hashes, approverHash) approvers.modified = true } } -func (approvers *Approvers) getHashes() (result []ternary.Trytes) { - result = make([]ternary.Trytes, len(approvers.hashes)) +func (approvers *Approvers) getHashes() (result []trinary.Trytes) { + result = make([]trinary.Trytes, len(approvers.hashes)) counter := 0 for hash := range approvers.hashes { diff --git a/packages/model/approvers/approvers_test.go b/packages/model/approvers/approvers_test.go index 5436330c..926c5c07 100644 --- a/packages/model/approvers/approvers_test.go +++ b/packages/model/approvers/approvers_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" "github.com/magiconair/properties/assert" ) func TestApprovers_SettersGetters(t *testing.T) { - hashA := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - hashB := ternary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + hashA := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + hashB := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") approversTest := New(hashA) approversTest.Add(hashB) @@ -19,8 +19,8 @@ func TestApprovers_SettersGetters(t *testing.T) { } func TestApprovers_MarshalUnmarshal(t *testing.T) { - hashA := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - hashB := ternary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + hashA := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + hashB := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") approversTest := New(hashA) approversTest.Add(hashB) diff --git a/packages/model/bundle/bundle.go b/packages/model/bundle/bundle.go index 88ff6cb1..3daec8d1 100644 --- a/packages/model/bundle/bundle.go +++ b/packages/model/bundle/bundle.go @@ -9,24 +9,24 @@ import ( "github.com/iotaledger/goshimmer/packages/bitutils" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/typeutils" - - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) type Bundle struct { - hash ternary.Trytes + hash trinary.Trytes hashMutex sync.RWMutex - transactionHashes []ternary.Trytes + transactionHashes []trinary.Trytes transactionHashesMutex sync.RWMutex isValueBundle bool isValueBundleMutex sync.RWMutex - bundleEssenceHash ternary.Trytes + bundleEssenceHash trinary.Trytes bundleEssenceHashMutex sync.RWMutex modified bool modifiedMutex sync.RWMutex } -func New(headTransactionHash ternary.Trytes) (result *Bundle) { +func New(headTransactionHash trinary.Trytes) (result *Bundle) { result = &Bundle{ hash: headTransactionHash, } @@ -34,7 +34,7 @@ func New(headTransactionHash ternary.Trytes) (result *Bundle) { return } -func (bundle *Bundle) GetHash() (result ternary.Trytes) { +func (bundle *Bundle) GetHash() (result trinary.Trytes) { bundle.hashMutex.RLock() result = bundle.hash bundle.hashMutex.RUnlock() @@ -42,13 +42,13 @@ func (bundle *Bundle) GetHash() (result ternary.Trytes) { return } -func (bundle *Bundle) SetHash(hash ternary.Trytes) { +func (bundle *Bundle) SetHash(hash trinary.Trytes) { bundle.hashMutex.Lock() bundle.hash = hash bundle.hashMutex.Unlock() } -func (bundle *Bundle) GetTransactionHashes() (result []ternary.Trytes) { +func (bundle *Bundle) GetTransactionHashes() (result []trinary.Trytes) { bundle.bundleEssenceHashMutex.RLock() result = bundle.transactionHashes bundle.bundleEssenceHashMutex.RUnlock() @@ -56,7 +56,7 @@ func (bundle *Bundle) GetTransactionHashes() (result []ternary.Trytes) { return } -func (bundle *Bundle) SetTransactionHashes(transactionHashes []ternary.Trytes) { +func (bundle *Bundle) SetTransactionHashes(transactionHashes []trinary.Trytes) { bundle.transactionHashesMutex.Lock() bundle.transactionHashes = transactionHashes bundle.transactionHashesMutex.Unlock() @@ -76,7 +76,7 @@ func (bundle *Bundle) SetValueBundle(valueBundle bool) { bundle.isValueBundleMutex.Unlock() } -func (bundle *Bundle) GetBundleEssenceHash() (result ternary.Trytes) { +func (bundle *Bundle) GetBundleEssenceHash() (result trinary.Trytes) { bundle.bundleEssenceHashMutex.RLock() result = bundle.bundleEssenceHash bundle.bundleEssenceHashMutex.RUnlock() @@ -84,7 +84,7 @@ func (bundle *Bundle) GetBundleEssenceHash() (result ternary.Trytes) { return } -func (bundle *Bundle) SetBundleEssenceHash(bundleEssenceHash ternary.Trytes) { +func (bundle *Bundle) SetBundleEssenceHash(bundleEssenceHash trinary.Trytes) { bundle.bundleEssenceHashMutex.Lock() bundle.bundleEssenceHash = bundleEssenceHash bundle.bundleEssenceHashMutex.Unlock() @@ -114,8 +114,8 @@ func (bundle *Bundle) Marshal() (result []byte) { binary.BigEndian.PutUint64(result[MARSHALED_TRANSACTIONS_COUNT_START:MARSHALED_TRANSACTIONS_COUNT_END], uint64(len(bundle.transactionHashes))) - copy(result[MARSHALED_HASH_START:MARSHALED_HASH_END], bundle.hash.CastToBytes()) - copy(result[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END], bundle.bundleEssenceHash.CastToBytes()) + copy(result[MARSHALED_HASH_START:MARSHALED_HASH_END], unsafeconvert.StringToBytes(bundle.hash)) + copy(result[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END], unsafeconvert.StringToBytes(bundle.bundleEssenceHash)) var flags bitutils.BitMask if bundle.isValueBundle { @@ -128,7 +128,7 @@ func (bundle *Bundle) Marshal() (result []byte) { var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_TRANSACTION_HASH_SIZE) var HASH_END = HASH_START + MARSHALED_TRANSACTION_HASH_SIZE - copy(result[HASH_START:HASH_END], hash.CastToBytes()) + copy(result[HASH_START:HASH_END], unsafeconvert.StringToBytes(hash)) i++ } @@ -159,20 +159,20 @@ func (bundle *Bundle) Unmarshal(data []byte) (err errors.IdentifiableError) { bundle.isValueBundleMutex.Lock() bundle.transactionHashesMutex.Lock() - bundle.hash = ternary.Trytes(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) - bundle.bundleEssenceHash = ternary.Trytes(typeutils.BytesToString(data[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END])) + bundle.hash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) + bundle.bundleEssenceHash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END])) flags := bitutils.BitMask(data[MARSHALED_FLAGS_START]) if flags.HasFlag(0) { bundle.isValueBundle = true } - bundle.transactionHashes = make([]ternary.Trytes, hashesCount) + bundle.transactionHashes = make([]trinary.Trytes, hashesCount) for i := uint64(0); i < hashesCount; i++ { var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_TRANSACTION_HASH_SIZE) var HASH_END = HASH_START + MARSHALED_TRANSACTION_HASH_SIZE - bundle.transactionHashes[i] = ternary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END])) + bundle.transactionHashes[i] = trinary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END])) } bundle.transactionHashesMutex.Unlock() diff --git a/packages/model/bundle/bundle_test.go b/packages/model/bundle/bundle_test.go index ee1b0e32..d00bb6ec 100644 --- a/packages/model/bundle/bundle_test.go +++ b/packages/model/bundle/bundle_test.go @@ -3,16 +3,16 @@ package bundle import ( "testing" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" "github.com/magiconair/properties/assert" ) func TestBundle_SettersGetters(t *testing.T) { - bundleHash := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - bundleEssenceHash := ternary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - transactions := []ternary.Trytes{ + bundleHash := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + bundleEssenceHash := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + transactions := []trinary.Trytes{ bundleHash, - ternary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), + trinary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), } testBundle := New(bundleHash) @@ -29,11 +29,11 @@ func TestBundle_SettersGetters(t *testing.T) { } func TestBundle_SettersGettersMarshalUnmarshal(t *testing.T) { - bundleHash := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - bundleEssenceHash := ternary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - transactions := []ternary.Trytes{ + bundleHash := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + bundleEssenceHash := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + transactions := []trinary.Trytes{ bundleHash, - ternary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), + trinary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), } testBundle := New(bundleHash) diff --git a/packages/model/meta_transaction/constants.go b/packages/model/meta_transaction/constants.go index 8676b4c9..1e5cbdcc 100644 --- a/packages/model/meta_transaction/constants.go +++ b/packages/model/meta_transaction/constants.go @@ -1,7 +1,7 @@ package meta_transaction import ( - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) const ( @@ -31,5 +31,5 @@ const ( MARSHALED_TOTAL_SIZE = DATA_END - BRANCH_NULL_HASH = ternary.Trytes("999999999999999999999999999999999999999999999999999999999999999999999999999999999") + BRANCH_NULL_HASH = trinary.Trytes("999999999999999999999999999999999999999999999999999999999999999999999999999999999") ) diff --git a/packages/model/meta_transaction/meta_transaction.go b/packages/model/meta_transaction/meta_transaction.go index 58669c8b..cd78f408 100644 --- a/packages/model/meta_transaction/meta_transaction.go +++ b/packages/model/meta_transaction/meta_transaction.go @@ -4,20 +4,20 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/curl" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) type MetaTransaction struct { - hash *ternary.Trytes + hash *trinary.Trytes weightMagnitude int - shardMarker *ternary.Trytes - trunkTransactionHash *ternary.Trytes - branchTransactionHash *ternary.Trytes + shardMarker *trinary.Trytes + trunkTransactionHash *trinary.Trytes + branchTransactionHash *trinary.Trytes head *bool tail *bool - transactionType *ternary.Trytes - data ternary.Trits + transactionType *trinary.Trytes + data trinary.Trits modified bool hasherMutex sync.RWMutex @@ -32,22 +32,27 @@ type MetaTransaction struct { bytesMutex sync.RWMutex modifiedMutex sync.RWMutex - trits ternary.Trits + trits trinary.Trits bytes []byte } func New() *MetaTransaction { - return FromTrits(make(ternary.Trits, MARSHALED_TOTAL_SIZE)) + return FromTrits(make(trinary.Trits, MARSHALED_TOTAL_SIZE)) } -func FromTrits(trits ternary.Trits) *MetaTransaction { +func FromTrits(trits trinary.Trits) *MetaTransaction { return &MetaTransaction{ trits: trits, } } func FromBytes(bytes []byte) (result *MetaTransaction) { - result = FromTrits(ternary.BytesToTrits(bytes)[:MARSHALED_TOTAL_SIZE]) + trits, err := trinary.BytesToTrits(bytes) + if err != nil { + panic(err) + } + + result = FromTrits(trits[:MARSHALED_TOTAL_SIZE]) result.bytes = bytes return @@ -72,7 +77,7 @@ func (this *MetaTransaction) ReHash() { } // retrieves the hash of the transaction -func (this *MetaTransaction) GetHash() (result ternary.Trytes) { +func (this *MetaTransaction) GetHash() (result trinary.Trytes) { this.hashMutex.RLock() if this.hash == nil { this.hashMutex.RUnlock() @@ -116,21 +121,21 @@ func (this *MetaTransaction) GetWeightMagnitude() (result int) { // hashes the transaction using curl (without locking - internal usage) func (this *MetaTransaction) parseHashRelatedDetails() { hashTrits := <-curl.CURLP81.Hash(this.trits) - hashTrytes := hashTrits.ToTrytes() + hashTrytes := trinary.MustTritsToTrytes(hashTrits) this.hash = &hashTrytes - this.weightMagnitude = hashTrits.TrailingZeroes() + this.weightMagnitude = int(trinary.TrailingZeros(hashTrits)) } // getter for the shard marker (supports concurrency) -func (this *MetaTransaction) GetShardMarker() (result ternary.Trytes) { +func (this *MetaTransaction) GetShardMarker() (result trinary.Trytes) { this.shardMarkerMutex.RLock() if this.shardMarker == nil { this.shardMarkerMutex.RUnlock() this.shardMarkerMutex.Lock() defer this.shardMarkerMutex.Unlock() if this.shardMarker == nil { - shardMarker := this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END].ToTrytes() + shardMarker := trinary.MustTritsToTrytes(this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END]) this.shardMarker = &shardMarker } @@ -144,7 +149,7 @@ func (this *MetaTransaction) GetShardMarker() (result ternary.Trytes) { } // setter for the shard marker (supports concurrency) -func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trytes) bool { +func (this *MetaTransaction) SetShardMarker(shardMarker trinary.Trytes) bool { this.shardMarkerMutex.RLock() if this.shardMarker == nil || *this.shardMarker != shardMarker { this.shardMarkerMutex.RUnlock() @@ -154,7 +159,7 @@ func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trytes) bool { this.shardMarker = &shardMarker this.hasherMutex.RLock() - copy(this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END], shardMarker.ToTrits()[:SHARD_MARKER_SIZE]) + copy(this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END], trinary.MustTrytesToTrits(shardMarker)[:SHARD_MARKER_SIZE]) this.hasherMutex.RUnlock() this.SetModified(true) @@ -170,14 +175,14 @@ func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trytes) bool { } // getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetTrunkTransactionHash() (result ternary.Trytes) { +func (this *MetaTransaction) GetTrunkTransactionHash() (result trinary.Trytes) { this.trunkTransactionHashMutex.RLock() if this.trunkTransactionHash == nil { this.trunkTransactionHashMutex.RUnlock() this.trunkTransactionHashMutex.Lock() defer this.trunkTransactionHashMutex.Unlock() if this.trunkTransactionHash == nil { - trunkTransactionHash := this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END].ToTrytes() + trunkTransactionHash := trinary.MustTritsToTrytes(this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END]) this.trunkTransactionHash = &trunkTransactionHash } @@ -191,7 +196,7 @@ func (this *MetaTransaction) GetTrunkTransactionHash() (result ternary.Trytes) { } // setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternary.Trytes) bool { +func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash trinary.Trytes) bool { this.trunkTransactionHashMutex.RLock() if this.trunkTransactionHash == nil || *this.trunkTransactionHash != trunkTransactionHash { this.trunkTransactionHashMutex.RUnlock() @@ -201,7 +206,7 @@ func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternar this.trunkTransactionHash = &trunkTransactionHash this.hasherMutex.RLock() - copy(this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END], trunkTransactionHash.ToTrits()[:TRUNK_TRANSACTION_HASH_SIZE]) + copy(this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END], trinary.MustTrytesToTrits(trunkTransactionHash)[:TRUNK_TRANSACTION_HASH_SIZE]) this.hasherMutex.RUnlock() this.SetModified(true) @@ -217,14 +222,14 @@ func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternar } // getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetBranchTransactionHash() (result ternary.Trytes) { +func (this *MetaTransaction) GetBranchTransactionHash() (result trinary.Trytes) { this.branchTransactionHashMutex.RLock() if this.branchTransactionHash == nil { this.branchTransactionHashMutex.RUnlock() this.branchTransactionHashMutex.Lock() defer this.branchTransactionHashMutex.Unlock() if this.branchTransactionHash == nil { - branchTransactionHash := this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END].ToTrytes() + branchTransactionHash := trinary.MustTritsToTrytes(this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END]) this.branchTransactionHash = &branchTransactionHash } @@ -238,7 +243,7 @@ func (this *MetaTransaction) GetBranchTransactionHash() (result ternary.Trytes) } // setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash ternary.Trytes) bool { +func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash trinary.Trytes) bool { this.branchTransactionHashMutex.RLock() if this.branchTransactionHash == nil || *this.branchTransactionHash != branchTransactionHash { this.branchTransactionHashMutex.RUnlock() @@ -248,7 +253,7 @@ func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash tern this.branchTransactionHash = &branchTransactionHash this.hasherMutex.RLock() - copy(this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END], branchTransactionHash.ToTrits()[:BRANCH_TRANSACTION_HASH_SIZE]) + copy(this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END], trinary.MustTrytesToTrits(branchTransactionHash)[:BRANCH_TRANSACTION_HASH_SIZE]) this.hasherMutex.RUnlock() this.SetModified(true) @@ -366,14 +371,14 @@ func (this *MetaTransaction) SetTail(tail bool) bool { } // getter for the transaction type (supports concurrency) -func (this *MetaTransaction) GetTransactionType() (result ternary.Trytes) { +func (this *MetaTransaction) GetTransactionType() (result trinary.Trytes) { this.transactionTypeMutex.RLock() if this.transactionType == nil { this.transactionTypeMutex.RUnlock() this.transactionTypeMutex.Lock() defer this.transactionTypeMutex.Unlock() if this.transactionType == nil { - transactionType := this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END].ToTrytes() + transactionType := trinary.MustTritsToTrytes(this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END]) this.transactionType = &transactionType } @@ -387,7 +392,7 @@ func (this *MetaTransaction) GetTransactionType() (result ternary.Trytes) { } // setter for the transaction type (supports concurrency) -func (this *MetaTransaction) SetTransactionType(transactionType ternary.Trytes) bool { +func (this *MetaTransaction) SetTransactionType(transactionType trinary.Trytes) bool { this.transactionTypeMutex.RLock() if this.transactionType == nil || *this.transactionType != transactionType { this.transactionTypeMutex.RUnlock() @@ -397,7 +402,7 @@ func (this *MetaTransaction) SetTransactionType(transactionType ternary.Trytes) this.transactionType = &transactionType this.hasherMutex.RLock() - copy(this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END], transactionType.ToTrits()[:TRANSACTION_TYPE_SIZE]) + copy(this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END], trinary.MustTrytesToTrits(transactionType)[:TRANSACTION_TYPE_SIZE]) this.hasherMutex.RUnlock() this.SetModified(true) @@ -413,7 +418,7 @@ func (this *MetaTransaction) SetTransactionType(transactionType ternary.Trytes) } // getter for the data slice (supports concurrency) -func (this *MetaTransaction) GetData() (result ternary.Trits) { +func (this *MetaTransaction) GetData() (result trinary.Trits) { this.dataMutex.RLock() if this.data == nil { this.dataMutex.RUnlock() @@ -431,8 +436,8 @@ func (this *MetaTransaction) GetData() (result ternary.Trits) { return } -func (this *MetaTransaction) GetTrits() (result ternary.Trits) { - result = make(ternary.Trits, len(this.trits)) +func (this *MetaTransaction) GetTrits() (result trinary.Trits) { + result = make(trinary.Trits, len(this.trits)) this.hasherMutex.Lock() copy(result, this.trits) @@ -449,7 +454,7 @@ func (this *MetaTransaction) GetBytes() (result []byte) { defer this.bytesMutex.Unlock() this.hasherMutex.Lock() - this.bytes = this.trits.ToBytes() + this.bytes = trinary.TritsToBytes(this.trits) this.hasherMutex.Unlock() } else { this.bytesMutex.RUnlock() diff --git a/packages/model/meta_transaction/meta_transaction_test.go b/packages/model/meta_transaction/meta_transaction_test.go index 1b10208d..2ba055b7 100644 --- a/packages/model/meta_transaction/meta_transaction_test.go +++ b/packages/model/meta_transaction/meta_transaction_test.go @@ -5,17 +5,17 @@ import ( "sync" "testing" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" "github.com/magiconair/properties/assert" ) func TestMetaTransaction_SettersGetters(t *testing.T) { - shardMarker := ternary.Trytes("NPHTQORL9XKA") - trunkTransactionHash := ternary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999A") - branchTransactionHash := ternary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999B") + shardMarker := trinary.Trytes("NPHTQORL9XKA") + trunkTransactionHash := trinary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999A") + branchTransactionHash := trinary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999B") head := true tail := true - transactionType := ternary.Trytes("9999999999999999999999") + transactionType := trinary.Trytes("9999999999999999999999") transaction := New() transaction.SetShardMarker(shardMarker) diff --git a/packages/model/transactionmetadata/transactionmetadata.go b/packages/model/transactionmetadata/transactionmetadata.go index f2518fdd..3f9e3b3a 100644 --- a/packages/model/transactionmetadata/transactionmetadata.go +++ b/packages/model/transactionmetadata/transactionmetadata.go @@ -6,16 +6,17 @@ import ( "github.com/iotaledger/goshimmer/packages/bitutils" "github.com/iotaledger/goshimmer/packages/errors" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) // region type definition and constructor ////////////////////////////////////////////////////////////////////////////// type TransactionMetadata struct { - hash ternary.Trytes + hash trinary.Trytes hashMutex sync.RWMutex - bundleHeadHash ternary.Trytes + bundleHeadHash trinary.Trytes bundleHeadHashMutex sync.RWMutex receivedTime time.Time receivedTimeMutex sync.RWMutex @@ -29,7 +30,7 @@ type TransactionMetadata struct { modifiedMutex sync.RWMutex } -func New(hash ternary.Trytes) *TransactionMetadata { +func New(hash trinary.Trytes) *TransactionMetadata { return &TransactionMetadata{ hash: hash, receivedTime: time.Now(), @@ -44,14 +45,14 @@ func New(hash ternary.Trytes) *TransactionMetadata { // region getters and setters ////////////////////////////////////////////////////////////////////////////////////////// -func (metadata *TransactionMetadata) GetHash() ternary.Trytes { +func (metadata *TransactionMetadata) GetHash() trinary.Trytes { metadata.hashMutex.RLock() defer metadata.hashMutex.RUnlock() return metadata.hash } -func (metadata *TransactionMetadata) SetHash(hash ternary.Trytes) { +func (metadata *TransactionMetadata) SetHash(hash trinary.Trytes) { metadata.hashMutex.RLock() if metadata.hash != hash { metadata.hashMutex.RUnlock() @@ -67,14 +68,14 @@ func (metadata *TransactionMetadata) SetHash(hash ternary.Trytes) { } } -func (metadata *TransactionMetadata) GetBundleHeadHash() ternary.Trytes { +func (metadata *TransactionMetadata) GetBundleHeadHash() trinary.Trytes { metadata.bundleHeadHashMutex.RLock() defer metadata.bundleHeadHashMutex.RUnlock() return metadata.bundleHeadHash } -func (metadata *TransactionMetadata) SetBundleHeadHash(bundleTailHash ternary.Trytes) { +func (metadata *TransactionMetadata) SetBundleHeadHash(bundleTailHash trinary.Trytes) { metadata.bundleHeadHashMutex.RLock() if metadata.bundleHeadHash != bundleTailHash { metadata.bundleHeadHashMutex.RUnlock() @@ -218,7 +219,7 @@ func (metadata *TransactionMetadata) Marshal() ([]byte, errors.IdentifiableError metadata.finalizedMutex.RLock() defer metadata.finalizedMutex.RUnlock() - copy(marshaledMetadata[MARSHALED_HASH_START:MARSHALED_HASH_END], metadata.hash.CastToBytes()) + copy(marshaledMetadata[MARSHALED_HASH_START:MARSHALED_HASH_END], unsafeconvert.StringToBytes(metadata.hash)) marshaledReceivedTime, err := metadata.receivedTime.MarshalBinary() if err != nil { @@ -253,7 +254,7 @@ func (metadata *TransactionMetadata) Unmarshal(data []byte) errors.IdentifiableE metadata.finalizedMutex.Lock() defer metadata.finalizedMutex.Unlock() - metadata.hash = ternary.Trytes(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) + metadata.hash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) if err := metadata.receivedTime.UnmarshalBinary(data[MARSHALED_RECEIVED_TIME_START:MARSHALED_RECEIVED_TIME_END]); err != nil { return ErrUnmarshalFailed.Derive(err, "could not unmarshal the received time") diff --git a/packages/model/value_transaction/constants.go b/packages/model/value_transaction/constants.go index b20a6d4f..cc2175fd 100644 --- a/packages/model/value_transaction/constants.go +++ b/packages/model/value_transaction/constants.go @@ -3,7 +3,7 @@ package value_transaction import ( "strings" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) const ( @@ -30,5 +30,5 @@ const ( ) var ( - EMPTY_SIGNATURE = ternary.Trytes(strings.Repeat("9", SIGNATURE_MESSAGE_FRAGMENT_SIZE/ternary.NUMBER_OF_TRITS_IN_A_TRYTE)) + EMPTY_SIGNATURE = trinary.Trytes(strings.Repeat("9", SIGNATURE_MESSAGE_FRAGMENT_SIZE/3)) ) diff --git a/packages/model/value_transaction/value_transaction.go b/packages/model/value_transaction/value_transaction.go index 20054207..398e90c0 100644 --- a/packages/model/value_transaction/value_transaction.go +++ b/packages/model/value_transaction/value_transaction.go @@ -4,24 +4,24 @@ import ( "sync" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) type ValueTransaction struct { *meta_transaction.MetaTransaction - address *ternary.Trytes + address *trinary.Trytes addressMutex sync.RWMutex value *int64 valueMutex sync.RWMutex timestamp *uint timestampMutex sync.RWMutex - nonce *ternary.Trytes + nonce *trinary.Trytes nonceMutex sync.RWMutex - signatureMessageFragment *ternary.Trytes + signatureMessageFragment *trinary.Trytes signatureMessageFragmentMutex sync.RWMutex - trits ternary.Trits + trits trinary.Trits } func New() (result *ValueTransaction) { @@ -42,8 +42,13 @@ func FromMetaTransaction(metaTransaction *meta_transaction.MetaTransaction) *Val } func FromBytes(bytes []byte) (result *ValueTransaction) { + trits, err := trinary.BytesToTrits(bytes) + if err != nil { + panic(err) + } + result = &ValueTransaction{ - MetaTransaction: meta_transaction.FromTrits(ternary.BytesToTrits(bytes)[:meta_transaction.MARSHALED_TOTAL_SIZE]), + MetaTransaction: meta_transaction.FromTrits(trits[:meta_transaction.MARSHALED_TOTAL_SIZE]), } result.trits = result.MetaTransaction.GetData() @@ -52,14 +57,14 @@ func FromBytes(bytes []byte) (result *ValueTransaction) { } // getter for the address (supports concurrency) -func (this *ValueTransaction) GetAddress() (result ternary.Trytes) { +func (this *ValueTransaction) GetAddress() (result trinary.Trytes) { this.addressMutex.RLock() if this.address == nil { this.addressMutex.RUnlock() this.addressMutex.Lock() defer this.addressMutex.Unlock() if this.address == nil { - address := this.trits[ADDRESS_OFFSET:ADDRESS_END].ToTrytes() + address := trinary.MustTritsToTrytes(this.trits[ADDRESS_OFFSET:ADDRESS_END]) this.address = &address } @@ -73,7 +78,7 @@ func (this *ValueTransaction) GetAddress() (result ternary.Trytes) { } // setter for the address (supports concurrency) -func (this *ValueTransaction) SetAddress(address ternary.Trytes) bool { +func (this *ValueTransaction) SetAddress(address trinary.Trytes) bool { this.addressMutex.RLock() if this.address == nil || *this.address != address { this.addressMutex.RUnlock() @@ -83,7 +88,7 @@ func (this *ValueTransaction) SetAddress(address ternary.Trytes) bool { this.address = &address this.BlockHasher() - copy(this.trits[ADDRESS_OFFSET:ADDRESS_END], address.ToTrits()[:ADDRESS_SIZE]) + copy(this.trits[ADDRESS_OFFSET:ADDRESS_END], trinary.MustTrytesToTrits(address)[:ADDRESS_SIZE]) this.UnblockHasher() this.SetModified(true) @@ -106,7 +111,7 @@ func (this *ValueTransaction) GetValue() (result int64) { this.valueMutex.Lock() defer this.valueMutex.Unlock() if this.value == nil { - value := this.trits[VALUE_OFFSET:VALUE_END].ToInt64() + value := trinary.TritsToInt(this.trits[VALUE_OFFSET:VALUE_END]) this.value = &value } @@ -130,7 +135,7 @@ func (this *ValueTransaction) SetValue(value int64) bool { this.value = &value this.BlockHasher() - copy(this.trits[VALUE_OFFSET:VALUE_END], ternary.Int64ToTrits(value)[:VALUE_SIZE]) + copy(this.trits[VALUE_OFFSET:], trinary.IntToTrits(value)) this.UnblockHasher() this.SetModified(true) @@ -153,7 +158,7 @@ func (this *ValueTransaction) GetTimestamp() (result uint) { this.timestampMutex.Lock() defer this.timestampMutex.Unlock() if this.timestamp == nil { - timestamp := this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END].ToUint() + timestamp := uint(trinary.TritsToInt(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END])) this.timestamp = ×tamp } @@ -177,7 +182,7 @@ func (this *ValueTransaction) SetTimestamp(timestamp uint) bool { this.timestamp = ×tamp this.BlockHasher() - copy(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END], ternary.UintToTrits(timestamp)[:TIMESTAMP_SIZE]) + copy(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END], trinary.IntToTrits(int64(timestamp))[:TIMESTAMP_SIZE]) this.UnblockHasher() this.SetModified(true) @@ -192,12 +197,12 @@ func (this *ValueTransaction) SetTimestamp(timestamp uint) bool { return false } -func (this *ValueTransaction) GetBundleEssence() (result ternary.Trits) { +func (this *ValueTransaction) GetBundleEssence() (result trinary.Trits) { this.addressMutex.RLock() this.valueMutex.RLock() this.signatureMessageFragmentMutex.RLock() - result = make(ternary.Trits, BUNDLE_ESSENCE_SIZE) + result = make(trinary.Trits, BUNDLE_ESSENCE_SIZE) copy(result[0:], this.trits[ADDRESS_OFFSET:VALUE_END]) @@ -213,14 +218,14 @@ func (this *ValueTransaction) GetBundleEssence() (result ternary.Trits) { } // getter for the nonce (supports concurrency) -func (this *ValueTransaction) GetNonce() (result ternary.Trytes) { +func (this *ValueTransaction) GetNonce() (result trinary.Trytes) { this.nonceMutex.RLock() if this.nonce == nil { this.nonceMutex.RUnlock() this.nonceMutex.Lock() defer this.nonceMutex.Unlock() if this.nonce == nil { - nonce := this.trits[NONCE_OFFSET:NONCE_END].ToTrytes() + nonce := trinary.MustTritsToTrytes(this.trits[NONCE_OFFSET:NONCE_END]) this.nonce = &nonce } @@ -234,7 +239,7 @@ func (this *ValueTransaction) GetNonce() (result ternary.Trytes) { } // setter for the nonce (supports concurrency) -func (this *ValueTransaction) SetNonce(nonce ternary.Trytes) bool { +func (this *ValueTransaction) SetNonce(nonce trinary.Trytes) bool { this.nonceMutex.RLock() if this.nonce == nil || *this.nonce != nonce { this.nonceMutex.RUnlock() @@ -244,7 +249,7 @@ func (this *ValueTransaction) SetNonce(nonce ternary.Trytes) bool { this.nonce = &nonce this.BlockHasher() - copy(this.trits[NONCE_OFFSET:NONCE_END], nonce.ToTrits()[:NONCE_SIZE]) + copy(this.trits[NONCE_OFFSET:NONCE_END], trinary.MustTrytesToTrits(nonce)[:NONCE_SIZE]) this.UnblockHasher() this.SetModified(true) @@ -260,14 +265,14 @@ func (this *ValueTransaction) SetNonce(nonce ternary.Trytes) bool { } // getter for the signatureMessageFragmetn (supports concurrency) -func (this *ValueTransaction) GetSignatureMessageFragment() (result ternary.Trytes) { +func (this *ValueTransaction) GetSignatureMessageFragment() (result trinary.Trytes) { this.signatureMessageFragmentMutex.RLock() if this.signatureMessageFragment == nil { this.signatureMessageFragmentMutex.RUnlock() this.signatureMessageFragmentMutex.Lock() defer this.signatureMessageFragmentMutex.Unlock() if this.signatureMessageFragment == nil { - signatureMessageFragment := this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END].ToTrytes() + signatureMessageFragment := trinary.MustTritsToTrytes(this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END]) this.signatureMessageFragment = &signatureMessageFragment } @@ -281,7 +286,7 @@ func (this *ValueTransaction) GetSignatureMessageFragment() (result ternary.Tryt } // setter for the nonce (supports concurrency) -func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragment ternary.Trytes) bool { +func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragment trinary.Trytes) bool { this.signatureMessageFragmentMutex.RLock() if this.signatureMessageFragment == nil || *this.signatureMessageFragment != signatureMessageFragment { this.signatureMessageFragmentMutex.RUnlock() @@ -291,7 +296,7 @@ func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragme this.signatureMessageFragment = &signatureMessageFragment this.BlockHasher() - copy(this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END], signatureMessageFragment.ToTrits()[:SIGNATURE_MESSAGE_FRAGMENT_SIZE]) + copy(this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END], trinary.MustTrytesToTrits(signatureMessageFragment)[:SIGNATURE_MESSAGE_FRAGMENT_SIZE]) this.UnblockHasher() this.SetModified(true) diff --git a/packages/model/value_transaction/value_transaction_test.go b/packages/model/value_transaction/value_transaction_test.go index dcc6eb39..c1f732d6 100644 --- a/packages/model/value_transaction/value_transaction_test.go +++ b/packages/model/value_transaction/value_transaction_test.go @@ -4,12 +4,12 @@ import ( "fmt" "testing" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" "github.com/magiconair/properties/assert" ) func TestValueTransaction_SettersGetters(t *testing.T) { - address := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + address := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") transaction := New() transaction.SetAddress(address) diff --git a/packages/ternary/bc_ternary_demultiplexer.go b/packages/ternary/bc_ternary_demultiplexer.go index cebbd95b..96733a74 100644 --- a/packages/ternary/bc_ternary_demultiplexer.go +++ b/packages/ternary/bc_ternary_demultiplexer.go @@ -1,5 +1,9 @@ package ternary +import ( + . "github.com/iotaledger/iota.go/trinary" +) + type BCTernaryDemultiplexer struct { bcTrits BCTrits } diff --git a/packages/ternary/bc_ternary_multiplexer.go b/packages/ternary/bc_ternary_multiplexer.go index b822e8b2..f98991b6 100644 --- a/packages/ternary/bc_ternary_multiplexer.go +++ b/packages/ternary/bc_ternary_multiplexer.go @@ -3,6 +3,8 @@ package ternary import ( "errors" "strconv" + + . "github.com/iotaledger/iota.go/trinary" ) type BCTernaryMultiplexer struct { diff --git a/packages/ternary/conversion.go b/packages/ternary/conversion.go deleted file mode 100644 index 7cc01646..00000000 --- a/packages/ternary/conversion.go +++ /dev/null @@ -1,179 +0,0 @@ -package ternary - -import ( - "bytes" -) - -const ( - NUMBER_OF_TRITS_IN_A_BYTE = 5 - NUMBER_OF_TRITS_IN_A_TRYTE = 3 -) - -var ( - TRYTES_TO_TRITS_MAP = map[rune][]int8{ - '9': Trits{0, 0, 0}, - 'A': Trits{1, 0, 0}, - 'B': Trits{-1, 1, 0}, - 'C': Trits{0, 1, 0}, - 'D': Trits{1, 1, 0}, - 'E': Trits{-1, -1, 1}, - 'F': Trits{0, -1, 1}, - 'G': Trits{1, -1, 1}, - 'H': Trits{-1, 0, 1}, - 'I': Trits{0, 0, 1}, - 'J': Trits{1, 0, 1}, - 'K': Trits{-1, 1, 1}, - 'L': Trits{0, 1, 1}, - 'M': Trits{1, 1, 1}, - 'N': Trits{-1, -1, -1}, - 'O': Trits{0, -1, -1}, - 'P': Trits{1, -1, -1}, - 'Q': Trits{-1, 0, -1}, - 'R': Trits{0, 0, -1}, - 'S': Trits{1, 0, -1}, - 'T': Trits{-1, 1, -1}, - 'U': Trits{0, 1, -1}, - 'V': Trits{1, 1, -1}, - 'W': Trits{-1, -1, 0}, - 'X': Trits{0, -1, 0}, - 'Y': Trits{1, -1, 0}, - 'Z': Trits{-1, 0, 0}, - } - - TRYTE_ALPHABET = []string{ - "9", "A", "B", "C", "D", "E", "F", "G", "H", - "I", "J", "K", "L", "M", "N", "O", "P", "Q", - "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - } - - BYTES_TO_TRITS = []Trit{ - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, -1, -1, - 1, 0, 0, 0, -1, 1, 0, 0, 1, -1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, - 0, -1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, -1, -1, -1, 1, 0, 0, -1, -1, 1, 0, 1, - -1, -1, 1, 0, -1, 0, -1, 1, 0, 0, 0, -1, 1, 0, 1, 0, -1, 1, 0, -1, 1, -1, 1, 0, 0, 1, -1, - 1, 0, 1, 1, -1, 1, 0, -1, -1, 0, 1, 0, 0, -1, 0, 1, 0, 1, -1, 0, 1, 0, -1, 0, 0, 1, 0, - 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, -1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, - 1, 1, 0, 0, -1, 1, 1, 0, 1, -1, 1, 1, 0, -1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, - 0, -1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, -1, -1, -1, -1, 1, 0, -1, -1, -1, 1, 1, - -1, -1, -1, 1, -1, 0, -1, -1, 1, 0, 0, -1, -1, 1, 1, 0, -1, -1, 1, -1, 1, -1, -1, 1, 0, 1, -1, - -1, 1, 1, 1, -1, -1, 1, -1, -1, 0, -1, 1, 0, -1, 0, -1, 1, 1, -1, 0, -1, 1, -1, 0, 0, -1, 1, - 0, 0, 0, -1, 1, 1, 0, 0, -1, 1, -1, 1, 0, -1, 1, 0, 1, 0, -1, 1, 1, 1, 0, -1, 1, -1, -1, - 1, -1, 1, 0, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 0, 1, -1, 1, 0, 0, 1, -1, 1, 1, 0, 1, -1, - 1, -1, 1, 1, -1, 1, 0, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 0, 1, 0, -1, -1, 0, 1, 1, - -1, -1, 0, 1, -1, 0, -1, 0, 1, 0, 0, -1, 0, 1, 1, 0, -1, 0, 1, -1, 1, -1, 0, 1, 0, 1, -1, - 0, 1, 1, 1, -1, 0, 1, -1, -1, 0, 0, 1, 0, -1, 0, 0, 1, 1, -1, 0, 0, 1, -1, 0, 0, 0, 1, - 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, -1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, -1, -1, - 1, 0, 1, 0, -1, 1, 0, 1, 1, -1, 1, 0, 1, -1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, - 1, -1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, -1, -1, -1, 1, 1, 0, -1, -1, 1, 1, 1, - -1, -1, 1, 1, -1, 0, -1, 1, 1, 0, 0, -1, 1, 1, 1, 0, -1, 1, 1, -1, 1, -1, 1, 1, 0, 1, -1, - 1, 1, 1, 1, -1, 1, 1, -1, -1, 0, 1, 1, 0, -1, 0, 1, 1, 1, -1, 0, 1, 1, -1, 0, 0, 1, 1, - 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, -1, -1, - 1, 1, 1, 0, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, - 1, -1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, 1, - -1, -1, -1, -1, -1, 0, -1, -1, -1, 0, 0, -1, -1, -1, 1, 0, -1, -1, -1, -1, 1, -1, -1, -1, 0, 1, -1, - -1, -1, 1, 1, -1, -1, -1, -1, -1, 0, -1, -1, 0, -1, 0, -1, -1, 1, -1, 0, -1, -1, -1, 0, 0, -1, -1, - 0, 0, 0, -1, -1, 1, 0, 0, -1, -1, -1, 1, 0, -1, -1, 0, 1, 0, -1, -1, 1, 1, 0, -1, -1, -1, -1, - 1, -1, -1, 0, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, 0, 0, 1, -1, -1, 1, 0, 1, -1, - -1, -1, 1, 1, -1, -1, 0, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, 0, -1, 1, - -1, -1, 0, -1, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 1, 0, -1, 0, -1, -1, 1, -1, 0, -1, 0, 1, -1, - 0, -1, 1, 1, -1, 0, -1, -1, -1, 0, 0, -1, 0, -1, 0, 0, -1, 1, -1, 0, 0, -1, -1, 0, 0, 0, -1, - 0, 0, 0, 0, -1, 1, 0, 0, 0, -1, -1, 1, 0, 0, -1, 0, 1, 0, 0, -1, 1, 1, 0, 0, -1, -1, -1, - 1, 0, -1, 0, -1, 1, 0, -1, 1, -1, 1, 0, -1, -1, 0, 1, 0, -1, 0, 0, 1, 0, -1, 1, 0, 1, 0, - -1, -1, 1, 1, 0, -1, 0, 1, 1, 0, -1, 1, 1, 1, 0, -1, -1, -1, -1, 1, -1, 0, -1, -1, 1, -1, 1, - -1, -1, 1, -1, -1, 0, -1, 1, -1, 0, 0, -1, 1, -1, 1, 0, -1, 1, -1, -1, 1, -1, 1, -1, 0, 1, -1, - 1, -1, 1, 1, -1, 1, -1, -1, -1, 0, 1, -1, 0, -1, 0, 1, -1, 1, -1, 0, 1, -1, -1, 0, 0, 1, -1, - 0, 0, 0, 1, -1, 1, 0, 0, 1, -1, -1, 1, 0, 1, -1, 0, 1, 0, 1, -1, 1, 1, 0, 1, -1, -1, -1, - 1, 1, -1, 0, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 0, 1, 1, -1, 0, 0, 1, 1, -1, 1, 0, 1, 1, - -1, -1, 1, 1, 1, -1, 0, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, 0, 1, - -1, -1, -1, 0, -1, 0, -1, -1, 0, 0, 0, -1, -1, 0, 1, 0, -1, -1, 0, -1, 1, -1, -1, 0, 0, 1, -1, - -1, 0, 1, 1, -1, -1, 0, -1, -1, 0, -1, 0, 0, -1, 0, -1, 0, 1, -1, 0, -1, 0, -1, 0, 0, -1, 0, - 0, 0, 0, -1, 0, 1, 0, 0, -1, 0, -1, 1, 0, -1, 0, 0, 1, 0, -1, 0, 1, 1, 0, -1, 0, -1, -1, - 1, -1, 0, 0, -1, 1, -1, 0, 1, -1, 1, -1, 0, -1, 0, 1, -1, 0, 0, 0, 1, -1, 0, 1, 0, 1, -1, - 0, -1, 1, 1, -1, 0, 0, 1, 1, -1, 0, 1, 1, 1, -1, 0, -1, -1, -1, 0, 0, 0, -1, -1, 0, 0, 1, - -1, -1, 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 0, -1, 1, -1, 0, 0, 0, 1, -1, - 0, 0, 1, 1, -1, 0, 0, -1, -1, 0, 0, 0, 0, -1, 0, 0, 0, 1, -1, 0, 0, 0, -1, 0, 0, 0, 0, - } -) - -func BytesToTrits(bytes []byte) Trits { - size := len(bytes) - trits := make([]Trit, size*NUMBER_OF_TRITS_IN_A_BYTE) - - for i := 0; i < size; i++ { - v := int(bytes[i]) - if int8(bytes[i]) < 0 { - v -= 13 - } - - for j := 0; j < NUMBER_OF_TRITS_IN_A_BYTE; j++ { - trits[i*NUMBER_OF_TRITS_IN_A_BYTE+j] = BYTES_TO_TRITS[v*NUMBER_OF_TRITS_IN_A_BYTE+j] - } - } - - return trits -} - -func Int64ToTrits(value int64) (result Trits) { - negative := value < 0 - shiftedValue := value >> 63 - valueAbs := (value ^ shiftedValue) - shiftedValue - - for valueAbs != 0 { - trit := Trit((valueAbs+1)%3 - 1) - if negative { - trit = -trit - } - result = append(result, trit) - valueAbs++ - valueAbs /= 3 - } - - for i := len(result); i < 81; i++ { - result = append(result, 0) - } - - return -} - -func UintToTrits(value uint) (result Trits) { - for value != 0 { - trit := Trit((value+1)%3 - 1) - result = append(result, trit) - value++ - value /= 3 - } - - for i := len(result); i < 27; i++ { - result = append(result, 0) - } - - return -} - -func Uint64ToTrits(value uint64) (result Trits) { - for value != 0 { - trit := Trit((value+1)%3 - 1) - result = append(result, trit) - value++ - value /= 3 - } - - for i := len(result); i < 81; i++ { - result = append(result, 0) - } - - return -} - -func TritsToString(trits Trits, offset int, size int) string { - var buffer bytes.Buffer - for i := 0; i < (size+NUMBER_OF_TRITS_IN_A_TRYTE-1)/NUMBER_OF_TRITS_IN_A_TRYTE; i++ { - j := int(trits[offset+i*NUMBER_OF_TRITS_IN_A_TRYTE]) + int(trits[offset+i*NUMBER_OF_TRITS_IN_A_TRYTE+1])*NUMBER_OF_TRITS_IN_A_TRYTE + int(trits[offset+i*NUMBER_OF_TRITS_IN_A_TRYTE+2])*NUMBER_OF_TRITS_IN_A_TRYTE*NUMBER_OF_TRITS_IN_A_TRYTE - if j < 0 { - j += len(TRYTE_ALPHABET) - } - buffer.WriteString(TRYTE_ALPHABET[j]) - } - - return buffer.String() -} diff --git a/packages/ternary/conversion_test.go b/packages/ternary/conversion_test.go deleted file mode 100644 index d7d16655..00000000 --- a/packages/ternary/conversion_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package ternary - -import ( - "testing" - - "github.com/magiconair/properties/assert" -) - -func TestInt64Conversion(t *testing.T) { - assert.Equal(t, Int64ToTrits(9223372036854775807).ToInt64(), int64(9223372036854775807)) - assert.Equal(t, Int64ToTrits(1337).ToInt64(), int64(1337)) - assert.Equal(t, Int64ToTrits(0).ToInt64(), int64(0)) - assert.Equal(t, Int64ToTrits(-1337).ToInt64(), int64(-1337)) - assert.Equal(t, Int64ToTrits(-9223372036854775808).ToInt64(), int64(-9223372036854775808)) -} - -func TestUInt64Conversion(t *testing.T) { - assert.Equal(t, Uint64ToTrits(18446744073709551615).ToUint64(), uint64(18446744073709551615)) - assert.Equal(t, Uint64ToTrits(1337).ToUint64(), uint64(1337)) - assert.Equal(t, Uint64ToTrits(0).ToUint64(), uint64(0)) -} diff --git a/packages/ternary/ternary.go b/packages/ternary/ternary.go deleted file mode 100644 index cedfbebd..00000000 --- a/packages/ternary/ternary.go +++ /dev/null @@ -1,105 +0,0 @@ -package ternary - -import ( - "reflect" - "unsafe" -) - -// a Trit can have the values 0, 1 and -1 -type Trit = int8 - -// Trits consists out of many Trits -type Trits []Trit - -// Trytes is a string representation of the Trits -type Trytes string - -// simply changes the type of this Trytes to a byte array without copying any data -func (trytes Trytes) CastToBytes() []byte { - hdr := (*reflect.StringHeader)(unsafe.Pointer(&trytes)) - - return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: hdr.Data, Len: hdr.Len, Cap: hdr.Len})) -} - -func (trytes Trytes) ToTrits() Trits { - trits := make(Trits, 0, len(trytes)*NUMBER_OF_TRITS_IN_A_TRYTE) - for _, char := range trytes { - trits = append(trits, TRYTES_TO_TRITS_MAP[char]...) - } - - return trits -} - -func (trytes Trytes) ToString() string { - return string(trytes) -} - -func (this Trits) ToBytes() []byte { - tritsLength := len(this) - bytesLength := (tritsLength + NUMBER_OF_TRITS_IN_A_BYTE - 1) / NUMBER_OF_TRITS_IN_A_BYTE - - bytes := make([]byte, bytesLength) - radix := int8(3) - - tritIdx := bytesLength * NUMBER_OF_TRITS_IN_A_BYTE - for byteNum := bytesLength - 1; byteNum >= 0; byteNum-- { - var value int8 = 0 - - for i := 0; i < NUMBER_OF_TRITS_IN_A_BYTE; i++ { - tritIdx-- - - if tritIdx < tritsLength { - value = value*radix + this[tritIdx] - } - } - bytes[byteNum] = byte(value) - } - - return bytes -} - -func (this Trits) TrailingZeroes() int { - zeros := 0 - index := len(this) - 1 - for index >= 0 && this[index] == 0 { - zeros++ - - index-- - } - - return zeros -} - -func (this Trits) ToUint() (result uint) { - for i := len(this) - 1; i >= 0; i-- { - result = result*3 + uint(this[i]) - } - - return -} - -func (this Trits) ToInt64() int64 { - var val int64 - for i := len(this) - 1; i >= 0; i-- { - val = val*3 + int64(this[i]) - } - - return val -} - -func (this Trits) ToUint64() uint64 { - var val uint64 - for i := len(this) - 1; i >= 0; i-- { - val = val*3 + uint64(this[i]) - } - - return val -} - -func (this Trits) ToString() string { - return TritsToString(this, 0, len(this)) -} - -func (this Trits) ToTrytes() Trytes { - return Trytes(TritsToString(this, 0, len(this))) -} diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index 30477231..3ff2a857 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -7,8 +7,8 @@ import ( "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/iota.go/trinary" ) var PLUGIN = node.NewPlugin("Bundle Processor", configure) @@ -25,7 +25,7 @@ func configure(plugin *node.Plugin) { func ProcessSolidBundleHead(headTransaction *value_transaction.ValueTransaction) (*bundle.Bundle, errors.IdentifiableError) { // only process the bundle if we didn't process it, yet - return tangle.GetBundle(headTransaction.GetHash(), func(headTransactionHash ternary.Trytes) (*bundle.Bundle, errors.IdentifiableError) { + return tangle.GetBundle(headTransaction.GetHash(), func(headTransactionHash trinary.Trytes) (*bundle.Bundle, errors.IdentifiableError) { // abort if bundle syntax is wrong if !headTransaction.IsHead() { return nil, ErrProcessBundleFailed.Derive(errors.New("invalid parameter"), "transaction needs to be head of bundle") @@ -85,8 +85,8 @@ func ProcessSolidBundleHead(headTransaction *value_transaction.ValueTransaction) }) } -func mapTransactionsToTransactionHashes(transactions []*value_transaction.ValueTransaction) (result []ternary.Trytes) { - result = make([]ternary.Trytes, len(transactions)) +func mapTransactionsToTransactionHashes(transactions []*value_transaction.ValueTransaction) (result []trinary.Trytes) { + result = make([]trinary.Trytes, len(transactions)) for k, v := range transactions { result[k] = v.GetHash() } diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index 6f0d789a..0f5081d4 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -56,5 +56,5 @@ func configure(ctx *node.Plugin) { } var PLUGIN = node.NewPlugin("CLI", configure, func(plugin *node.Plugin) { - + }) diff --git a/plugins/gossip/protocol_v1.go b/plugins/gossip/protocol_v1.go index ac5939a6..aa4e9d30 100644 --- a/plugins/gossip/protocol_v1.go +++ b/plugins/gossip/protocol_v1.go @@ -10,7 +10,7 @@ import ( "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/consts" ) // region protocolV1 /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -303,7 +303,7 @@ type transactionStateV1 struct { func newTransactionStateV1(protocol *protocol) *transactionStateV1 { return &transactionStateV1{ protocol: protocol, - buffer: make([]byte, meta_transaction.MARSHALED_TOTAL_SIZE/ternary.NUMBER_OF_TRITS_IN_A_BYTE), + buffer: make([]byte, meta_transaction.MARSHALED_TOTAL_SIZE/consts.NumberOfTritsInAByte), offset: 0, } } @@ -312,10 +312,10 @@ func (state *transactionStateV1) Receive(data []byte, offset int, length int) (i bytesRead := byteutils.ReadAvailableBytesToBuffer(state.buffer, state.offset, data, offset, length) state.offset += bytesRead - if state.offset == meta_transaction.MARSHALED_TOTAL_SIZE/ternary.NUMBER_OF_TRITS_IN_A_BYTE { + if state.offset == meta_transaction.MARSHALED_TOTAL_SIZE/consts.NumberOfTritsInAByte { protocol := state.protocol - transactionData := make([]byte, meta_transaction.MARSHALED_TOTAL_SIZE/ternary.NUMBER_OF_TRITS_IN_A_BYTE) + transactionData := make([]byte, meta_transaction.MARSHALED_TOTAL_SIZE/consts.NumberOfTritsInAByte) copy(transactionData, state.buffer) protocol.Events.ReceiveTransactionData.Trigger(transactionData) diff --git a/plugins/gossip/transaction_processor_test.go b/plugins/gossip/transaction_processor_test.go index 9c7e8bdf..082eba9d 100644 --- a/plugins/gossip/transaction_processor_test.go +++ b/plugins/gossip/transaction_processor_test.go @@ -5,11 +5,11 @@ import ( "testing" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/consts" ) func BenchmarkProcessSimilarTransactionsFiltered(b *testing.B) { - byteArray := setupTransaction(meta_transaction.MARSHALED_TOTAL_SIZE / ternary.NUMBER_OF_TRITS_IN_A_BYTE) + byteArray := setupTransaction(meta_transaction.MARSHALED_TOTAL_SIZE / consts.NumberOfTritsInAByte) b.ResetTimer() @@ -19,7 +19,7 @@ func BenchmarkProcessSimilarTransactionsFiltered(b *testing.B) { } func BenchmarkProcessSimilarTransactionsUnfiltered(b *testing.B) { - byteArray := setupTransaction(meta_transaction.MARSHALED_TOTAL_SIZE / ternary.NUMBER_OF_TRITS_IN_A_BYTE) + byteArray := setupTransaction(meta_transaction.MARSHALED_TOTAL_SIZE / consts.NumberOfTritsInAByte) b.ResetTimer() diff --git a/plugins/tangle/approvers.go b/plugins/tangle/approvers.go index a5648c8f..a692092c 100644 --- a/plugins/tangle/approvers.go +++ b/plugins/tangle/approvers.go @@ -7,13 +7,14 @@ import ( "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/approvers" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) // region global public api //////////////////////////////////////////////////////////////////////////////////////////// // GetApprovers retrieves approvers from the database. -func GetApprovers(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *approvers.Approvers) (result *approvers.Approvers, err errors.IdentifiableError) { +func GetApprovers(transactionHash trinary.Trytes, computeIfAbsent ...func(trinary.Trytes) *approvers.Approvers) (result *approvers.Approvers, err errors.IdentifiableError) { if cacheResult := approversCache.ComputeIfAbsent(transactionHash, func() interface{} { if dbApprovers, dbErr := getApproversFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -35,7 +36,7 @@ func GetApprovers(transactionHash ternary.Trytes, computeIfAbsent ...func(ternar return } -func ContainsApprovers(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { +func ContainsApprovers(transactionHash trinary.Trytes) (result bool, err errors.IdentifiableError) { if approversCache.Contains(transactionHash) { result = true } else { @@ -85,7 +86,7 @@ func configureApproversDatabase(plugin *node.Plugin) { func storeApproversInDatabase(approvers *approvers.Approvers) errors.IdentifiableError { if approvers.GetModified() { - if err := approversDatabase.Set(approvers.GetHash().CastToBytes(), approvers.Marshal()); err != nil { + if err := approversDatabase.Set(unsafeconvert.StringToBytes(approvers.GetHash()), approvers.Marshal()); err != nil { return ErrDatabaseError.Derive(err, "failed to store approvers") } @@ -95,8 +96,8 @@ func storeApproversInDatabase(approvers *approvers.Approvers) errors.Identifiabl return nil } -func getApproversFromDatabase(transactionHash ternary.Trytes) (*approvers.Approvers, errors.IdentifiableError) { - approversData, err := approversDatabase.Get(transactionHash.CastToBytes()) +func getApproversFromDatabase(transactionHash trinary.Trytes) (*approvers.Approvers, errors.IdentifiableError) { + approversData, err := approversDatabase.Get(unsafeconvert.StringToBytes(transactionHash)) if err != nil { if err == badger.ErrKeyNotFound { return nil, nil @@ -113,8 +114,8 @@ func getApproversFromDatabase(transactionHash ternary.Trytes) (*approvers.Approv return &result, nil } -func databaseContainsApprovers(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { - if contains, err := approversDatabase.Contains(transactionHash.CastToBytes()); err != nil { +func databaseContainsApprovers(transactionHash trinary.Trytes) (bool, errors.IdentifiableError) { + if contains, err := approversDatabase.Contains(unsafeconvert.StringToBytes(transactionHash)); err != nil { return false, ErrDatabaseError.Derive(err, "failed to check if the approvers exists") } else { return contains, nil diff --git a/plugins/tangle/bundle.go b/plugins/tangle/bundle.go index 38259be9..759041c4 100644 --- a/plugins/tangle/bundle.go +++ b/plugins/tangle/bundle.go @@ -7,13 +7,14 @@ import ( "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) // region global public api //////////////////////////////////////////////////////////////////////////////////////////// // GetBundle retrieves bundle from the database. -func GetBundle(headerTransactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) (*bundle.Bundle, errors.IdentifiableError)) (result *bundle.Bundle, err errors.IdentifiableError) { +func GetBundle(headerTransactionHash trinary.Trytes, computeIfAbsent ...func(trinary.Trytes) (*bundle.Bundle, errors.IdentifiableError)) (result *bundle.Bundle, err errors.IdentifiableError) { if cacheResult := bundleCache.ComputeIfAbsent(headerTransactionHash, func() interface{} { if dbBundle, dbErr := getBundleFromDatabase(headerTransactionHash); dbErr != nil { err = dbErr @@ -39,7 +40,7 @@ func GetBundle(headerTransactionHash ternary.Trytes, computeIfAbsent ...func(ter return } -func ContainsBundle(headerTransactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { +func ContainsBundle(headerTransactionHash trinary.Trytes) (result bool, err errors.IdentifiableError) { if bundleCache.Contains(headerTransactionHash) { result = true } else { @@ -89,7 +90,7 @@ func configureBundleDatabase(plugin *node.Plugin) { func storeBundleInDatabase(bundle *bundle.Bundle) errors.IdentifiableError { if bundle.GetModified() { - if err := bundleDatabase.Set(bundle.GetHash().CastToBytes(), bundle.Marshal()); err != nil { + if err := bundleDatabase.Set(unsafeconvert.StringToBytes(bundle.GetHash()), bundle.Marshal()); err != nil { return ErrDatabaseError.Derive(err, "failed to store bundle") } @@ -99,8 +100,8 @@ func storeBundleInDatabase(bundle *bundle.Bundle) errors.IdentifiableError { return nil } -func getBundleFromDatabase(transactionHash ternary.Trytes) (*bundle.Bundle, errors.IdentifiableError) { - bundleData, err := bundleDatabase.Get(transactionHash.CastToBytes()) +func getBundleFromDatabase(transactionHash trinary.Trytes) (*bundle.Bundle, errors.IdentifiableError) { + bundleData, err := bundleDatabase.Get(unsafeconvert.StringToBytes(transactionHash)) if err != nil { if err == badger.ErrKeyNotFound { return nil, nil @@ -117,8 +118,8 @@ func getBundleFromDatabase(transactionHash ternary.Trytes) (*bundle.Bundle, erro return &result, nil } -func databaseContainsBundle(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { - if contains, err := bundleDatabase.Contains(transactionHash.CastToBytes()); err != nil { +func databaseContainsBundle(transactionHash trinary.Trytes) (bool, errors.IdentifiableError) { + if contains, err := bundleDatabase.Contains(unsafeconvert.StringToBytes(transactionHash)); err != nil { return false, ErrDatabaseError.Derive(err, "failed to check if the bundle exists") } else { return contains, nil diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index ce66662a..69cd07e9 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -9,8 +9,8 @@ import ( "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/iota.go/trinary" ) // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// @@ -114,7 +114,7 @@ func IsSolid(transaction *value_transaction.ValueTransaction) (bool, errors.Iden return false, nil } -func propagateSolidity(transactionHash ternary.Trytes) errors.IdentifiableError { +func propagateSolidity(transactionHash trinary.Trytes) errors.IdentifiableError { if approvers, err := GetApprovers(transactionHash, approvers.New); err != nil { return err } else { @@ -138,7 +138,7 @@ func propagateSolidity(transactionHash ternary.Trytes) errors.IdentifiableError func processMetaTransaction(plugin *node.Plugin, metaTransaction *meta_transaction.MetaTransaction) { var newTransaction bool - if tx, err := GetTransaction(metaTransaction.GetHash(), func(transactionHash ternary.Trytes) *value_transaction.ValueTransaction { + if tx, err := GetTransaction(metaTransaction.GetHash(), func(transactionHash trinary.Trytes) *value_transaction.ValueTransaction { newTransaction = true return value_transaction.FromMetaTransaction(metaTransaction) diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index c35e8a9f..c7b04e9f 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -6,8 +6,8 @@ import ( "github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/iota.go/trinary" ) func TestSolidifier(t *testing.T) { @@ -19,7 +19,7 @@ func TestSolidifier(t *testing.T) { // create transactions and chain them together transaction1 := value_transaction.New() - transaction1.SetNonce(ternary.Trytes("99999999999999999999999999A")) + transaction1.SetNonce(trinary.Trytes("99999999999999999999999999A")) transaction2 := value_transaction.New() transaction2.SetBranchTransactionHash(transaction1.GetHash()) transaction3 := value_transaction.New() diff --git a/plugins/tangle/transaction.go b/plugins/tangle/transaction.go index be61b95c..b30074ee 100644 --- a/plugins/tangle/transaction.go +++ b/plugins/tangle/transaction.go @@ -7,13 +7,14 @@ import ( "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) // region public api /////////////////////////////////////////////////////////////////////////////////////////////////// -func GetTransaction(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *value_transaction.ValueTransaction) (result *value_transaction.ValueTransaction, err errors.IdentifiableError) { +func GetTransaction(transactionHash trinary.Trytes, computeIfAbsent ...func(trinary.Trytes) *value_transaction.ValueTransaction) (result *value_transaction.ValueTransaction, err errors.IdentifiableError) { if cacheResult := transactionCache.ComputeIfAbsent(transactionHash, func() interface{} { if transaction, dbErr := getTransactionFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -35,7 +36,7 @@ func GetTransaction(transactionHash ternary.Trytes, computeIfAbsent ...func(tern return } -func ContainsTransaction(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { +func ContainsTransaction(transactionHash trinary.Trytes) (result bool, err errors.IdentifiableError) { if transactionCache.Contains(transactionHash) { result = true } else { @@ -87,7 +88,7 @@ func configureTransactionDatabase(plugin *node.Plugin) { func storeTransactionInDatabase(transaction *value_transaction.ValueTransaction) errors.IdentifiableError { if transaction.GetModified() { - if err := transactionDatabase.Set(transaction.GetHash().CastToBytes(), transaction.MetaTransaction.GetBytes()); err != nil { + if err := transactionDatabase.Set(unsafeconvert.StringToBytes(transaction.GetHash()), transaction.MetaTransaction.GetBytes()); err != nil { return ErrDatabaseError.Derive(err, "failed to store transaction") } @@ -97,8 +98,8 @@ func storeTransactionInDatabase(transaction *value_transaction.ValueTransaction) return nil } -func getTransactionFromDatabase(transactionHash ternary.Trytes) (*value_transaction.ValueTransaction, errors.IdentifiableError) { - txData, err := transactionDatabase.Get(transactionHash.CastToBytes()) +func getTransactionFromDatabase(transactionHash trinary.Trytes) (*value_transaction.ValueTransaction, errors.IdentifiableError) { + txData, err := transactionDatabase.Get(unsafeconvert.StringToBytes(transactionHash)) if err != nil { if err == badger.ErrKeyNotFound { return nil, nil @@ -110,8 +111,8 @@ func getTransactionFromDatabase(transactionHash ternary.Trytes) (*value_transact return value_transaction.FromBytes(txData), nil } -func databaseContainsTransaction(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { - if contains, err := transactionDatabase.Contains(transactionHash.CastToBytes()); err != nil { +func databaseContainsTransaction(transactionHash trinary.Trytes) (bool, errors.IdentifiableError) { + if contains, err := transactionDatabase.Contains(unsafeconvert.StringToBytes(transactionHash)); err != nil { return contains, ErrDatabaseError.Derive(err, "failed to check if the transaction exists") } else { return contains, nil diff --git a/plugins/tangle/transaction_metadata.go b/plugins/tangle/transaction_metadata.go index 82a3b8fd..9387b2e3 100644 --- a/plugins/tangle/transaction_metadata.go +++ b/plugins/tangle/transaction_metadata.go @@ -7,13 +7,14 @@ import ( "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/goshimmer/packages/unsafeconvert" + "github.com/iotaledger/iota.go/trinary" ) // region public api /////////////////////////////////////////////////////////////////////////////////////////////////// -func GetTransactionMetadata(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *transactionmetadata.TransactionMetadata) (result *transactionmetadata.TransactionMetadata, err errors.IdentifiableError) { +func GetTransactionMetadata(transactionHash trinary.Trytes, computeIfAbsent ...func(trinary.Trytes) *transactionmetadata.TransactionMetadata) (result *transactionmetadata.TransactionMetadata, err errors.IdentifiableError) { if cacheResult := transactionMetadataCache.ComputeIfAbsent(transactionHash, func() interface{} { if transactionMetadata, dbErr := getTransactionMetadataFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -35,7 +36,7 @@ func GetTransactionMetadata(transactionHash ternary.Trytes, computeIfAbsent ...f return } -func ContainsTransactionMetadata(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { +func ContainsTransactionMetadata(transactionHash trinary.Trytes) (result bool, err errors.IdentifiableError) { if transactionMetadataCache.Contains(transactionHash) { result = true } else { @@ -90,7 +91,7 @@ func storeTransactionMetadataInDatabase(metadata *transactionmetadata.Transactio if marshaledMetadata, err := metadata.Marshal(); err != nil { return err } else { - if err := transactionMetadataDatabase.Set(metadata.GetHash().CastToBytes(), marshaledMetadata); err != nil { + if err := transactionMetadataDatabase.Set(unsafeconvert.StringToBytes(metadata.GetHash()), marshaledMetadata); err != nil { return ErrDatabaseError.Derive(err, "failed to store transaction metadata") } @@ -101,8 +102,8 @@ func storeTransactionMetadataInDatabase(metadata *transactionmetadata.Transactio return nil } -func getTransactionMetadataFromDatabase(transactionHash ternary.Trytes) (*transactionmetadata.TransactionMetadata, errors.IdentifiableError) { - txMetadata, err := transactionMetadataDatabase.Get(transactionHash.CastToBytes()) +func getTransactionMetadataFromDatabase(transactionHash trinary.Trytes) (*transactionmetadata.TransactionMetadata, errors.IdentifiableError) { + txMetadata, err := transactionMetadataDatabase.Get(unsafeconvert.StringToBytes(transactionHash)) if err != nil { if err == badger.ErrKeyNotFound { return nil, nil @@ -119,8 +120,8 @@ func getTransactionMetadataFromDatabase(transactionHash ternary.Trytes) (*transa return &result, nil } -func databaseContainsTransactionMetadata(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { - if contains, err := transactionMetadataDatabase.Contains(transactionHash.CastToBytes()); err != nil { +func databaseContainsTransactionMetadata(transactionHash trinary.Trytes) (bool, errors.IdentifiableError) { + if contains, err := transactionMetadataDatabase.Contains(unsafeconvert.StringToBytes(transactionHash)); err != nil { return contains, ErrDatabaseError.Derive(err, "failed to check if the transaction metadata exists") } else { return contains, nil diff --git a/plugins/tipselection/tipselection.go b/plugins/tipselection/tipselection.go index 5c05fd4b..34eb31e6 100644 --- a/plugins/tipselection/tipselection.go +++ b/plugins/tipselection/tipselection.go @@ -3,14 +3,14 @@ package tipselection import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/ternary" + "github.com/iotaledger/iota.go/trinary" ) var tips = datastructure.NewRandomMap() -func GetRandomTip() (result ternary.Trytes) { +func GetRandomTip() (result trinary.Trytes) { if randomTipHash := tips.RandomEntry(); randomTipHash != nil { - result = randomTipHash.(ternary.Trytes) + result = randomTipHash.(trinary.Trytes) } else { result = meta_transaction.BRANCH_NULL_HASH } diff --git a/plugins/webapi-gtta/plugin.go b/plugins/webapi-gtta/plugin.go index 6055ffdf..0ebad673 100644 --- a/plugins/webapi-gtta/plugin.go +++ b/plugins/webapi-gtta/plugin.go @@ -5,9 +5,9 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/node" - "github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/iota.go/trinary" "github.com/labstack/echo" ) @@ -30,6 +30,6 @@ func Handler(c echo.Context) error { type webResponse struct { Duration int64 `json:"duration"` - BranchTransaction ternary.Trytes `json:"branchTransaction"` - TrunkTransaction ternary.Trytes `json:"trunkTransaction"` + BranchTransaction trinary.Trytes `json:"branchTransaction"` + TrunkTransaction trinary.Trytes `json:"trunkTransaction"` } diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index 7d4472cd..4db21355 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -78,16 +78,16 @@ func publishTx(tx *value_transaction.ValueTransaction) error { messages := []string{ "tx", // ZMQ event - hash.ToString(), // Transaction hash - address.ToString(), // Address + hash, // Transaction hash + address, // Address strconv.FormatInt(value, 10), // Value emptyTag, // Obsolete tag strconv.FormatInt(timestamp, 10), // Timestamp "0", // Index of the transaction in the bundle "0", // Last transaction index of the bundle - hash.ToString(), // Bundle hash - trunk.ToString(), // Trunk transaction hash - branch.ToString(), // Branch transaction hash + hash, // Bundle hash + trunk, // Trunk transaction hash + branch, // Branch transaction hash strconv.FormatInt(stored, 10), // Unix timestamp for when the transaction was received emptyTag, // Tag } -- GitLab