Skip to content

Commit

Permalink
rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Oct 28, 2020
1 parent 02d3035 commit 27be41e
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 55 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ A library for working with [Magic Attribute Protocol](https://github.com/rohenaz

```go
import "github.com/rohenaz/go-bob"
mapp import "github.com/rohenaz/go-map"
import "github.com/rohenaz/go-map"

line := "<BOB formatted json string>"

bobData := bob.New()
if err := json.Unmarshal(line, &bobData); err != nil {
bobData := &bob.Tx{}
if err := json.Unmarshal(line, bobData); err != nil {
fmt.Println("Error:", err)
return
}

for _, out := range bobData.Out {
for _, tape := range out.Tape {
mapData := mapp.New()
mapData.FromTape(tape)
mapData, err := magic.NewFromTape(tape)
log.Printf("MAP TYPE is %s", mapData["type"])
}
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/rohenaz/go-map
module github.com/bitcoinschema/go-map

go 1.14
go 1.15

require github.com/rohenaz/go-bob v0.0.0-20200704190822-4b02dd80ee80
require github.com/bitcoinschema/go-bob v0.0.5
70 changes: 68 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
github.com/rohenaz/go-bob v0.0.0-20200704190822-4b02dd80ee80 h1:lxaVlf9j6iTQ+nYA67ph7B7H/id/uJ6RIXe9F549zKE=
github.com/rohenaz/go-bob v0.0.0-20200704190822-4b02dd80ee80/go.mod h1:YEjUooBSmI0F5qcDnyms7/xe8TdYZNcQrdQhOJ16fvY=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/bitcoinschema/go-bitcoin v0.2.5 h1:258yHVqr4bo8D78UO+Nj3fF3GiqWDrYcESXC9LiFgdQ=
github.com/bitcoinschema/go-bitcoin v0.2.5/go.mod h1:DbEPU/krXiht+Jh5QbpHTJnj/vilMBFAaCGbV5a6IQk=
github.com/bitcoinschema/go-bob v0.0.5 h1:0keqcxs2wdb68IDfUO/XQQmmC8ktHzPz3N5Mw3nRnvg=
github.com/bitcoinschema/go-bob v0.0.5/go.mod h1:HTIt/BWRAGfz4gs1DYnxGAsUw5JmarPyKDpPZNNCabs=
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 h1:2yTIV9u7H0BhRDGXH5xrAwAz7XibWJtX2dNezMeNsUo=
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173/go.mod h1:BZ1UcC9+tmcDEcdVXgpt13hMczwJxWzpAn68wNs7zRA=
github.com/bitcoinsv/bsvlog v0.0.0-20181216181007-cb81b076bf2e h1:6f+gRvaPE/4h0g39dqTNPr9/P4mikw0aB+dhiExaWN8=
github.com/bitcoinsv/bsvlog v0.0.0-20181216181007-cb81b076bf2e/go.mod h1:WPrWor6cSeuGQZ15qPe+jqFmblJEFrJHYfr5cD7cmyk=
github.com/bitcoinsv/bsvutil v0.0.0-20181216182056-1d77cf353ea9 h1:hFI8rT84FCA0FFy3cFrkW5Nz4FyNKlIdCvEvvTNySKg=
github.com/bitcoinsv/bsvutil v0.0.0-20181216182056-1d77cf353ea9/go.mod h1:p44KuNKUH5BC8uX4ONEODaHUR4+ibC8todEAOGQEJAM=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.21.0-beta h1:At9hIZdJW0s9E/fAz28nrz6AmcNlSVucCH796ZteX1M=
github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/itchyny/base58-go v0.1.0 h1:zF5spLDo956exUAD17o+7GamZTRkXOZlqJjRciZwd1I=
github.com/itchyny/base58-go v0.1.0/go.mod h1:SrMWPE3DFuJJp1M/RUhu4fccp/y9AlB8AL3o3duPToU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/libsv/libsv v0.0.11 h1:tb2w/RFpsZLEfPNDGl4tlwk3haMSXYXKspta16+nyv4=
github.com/libsv/libsv v0.0.11/go.mod h1:jhXD2sLtYUNMWoD9mWmsQN0hoGZUK1wCvindT1Odijo=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/piotrnar/gocoin v0.0.0-20201004105208-19152002e94e h1:GxCWyrs5rRKX+ntbqWGCjquzK99g6vIOMmrXzMOWC2E=
github.com/piotrnar/gocoin v0.0.0-20201004105208-19152002e94e/go.mod h1:sW6i99ojgdRHcz53PCjyEeoTEDFh9dfP5iiEIiNfcaM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/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/sync v0.0.0-20180314180146-1d60e4601c6f/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
62 changes: 32 additions & 30 deletions mapp.go → magic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mapp
package magic

import (
"fmt"

"github.com/rohenaz/go-bob"
"github.com/bitcoinschema/go-bob"
)

// MAP is Magic Attribute Protocol
Expand All @@ -14,21 +14,16 @@ const Prefix = "1PuQa7K62MiKCtssSLKy1kh56WWU7MtUR5"

// MAP Commands
const (
CMD = "CMD"
SET = "SET"
ADD = "ADD"
DELETE = "DELETE"
REMOVE = "REMOVE"
SELECT = "SELECT"
TXID = "TXID"
SELECT_CMD = "SELECT_CMD"
Cmd = "CMD"
Set = "SET"
Add = "ADD"
Delete = "DELETE"
Remove = "REMOVE"
Select = "SELECT"
TxID = "TXID"
SelectCmd = "SELECT_CMD"
)

// New creates a new MAP
func New() *MAP {
return &MAP{}
}

// MAP SET
func (m MAP) set(cells []bob.Cell) {
for idx, cell := range cells {
Expand Down Expand Up @@ -68,46 +63,53 @@ func (m MAP) delete(cells []bob.Cell) {
m["value"] = cells[3].S
}

// NewFromTape takes a tape and returns a new MAP
func NewFromTape(tape *bob.Tape) (magicTx *MAP, err error) {
magicTx = new(MAP)
err = magicTx.FromTape(tape)
return
}

// FromTape sets a MAP object from a BOB Tape
func (m MAP) FromTape(tape bob.Tape) error {
func (m MAP) FromTape(tape *bob.Tape) error {

if len(tape.Cell) < 3 {
return fmt.Errorf("Invalid MAP record. Missing require parameters %d", len(tape.Cell))
}

if tape.Cell[0].S == Prefix {
m[CMD] = tape.Cell[1].S
m[Cmd] = tape.Cell[1].S

switch m[CMD] {
case DELETE:
switch m[Cmd] {
case Delete:
m.delete(tape.Cell)
case ADD:
case Add:
m.add(tape.Cell)
case REMOVE:
case Remove:
m.remove(tape.Cell)
case SET:
case Set:
m.set(tape.Cell)
case SELECT:
case Select:
if len(tape.Cell) < 5 {
return fmt.Errorf("Missing required parameters in MAP SELECT statement. Cell length: %d", len(tape.Cell))
}
if len(tape.Cell[2].S) != 64 {
return fmt.Errorf("MAP syntax error. Invalid Txid in SELECT command: %d", len(tape.Cell))
}
m[TXID] = tape.Cell[2].S
m[SELECT_CMD] = tape.Cell[3].S
m[TxID] = tape.Cell[2].S
m[SelectCmd] = tape.Cell[3].S

// Build new command from SELECT
newCells := []bob.Cell{{S: Prefix}, {S: tape.Cell[3].S}}
newCells = append(newCells, tape.Cell[4:]...)
switch m[SELECT_CMD] {
case ADD:
switch m[SelectCmd] {
case Add:
m.add(newCells)
case DELETE:
case Delete:
m.delete(newCells)
case SET:
case Set:
m.set(newCells)
case REMOVE:
case Remove:
m.remove(newCells)
}
}
Expand Down
30 changes: 15 additions & 15 deletions mapp_test.go → magic_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mapp
package magic

import (
"testing"

"github.com/rohenaz/go-bob"
"github.com/bitcoinschema/go-bob"
)

func contains(arr []string, str string) bool {
Expand All @@ -19,32 +19,32 @@ func TestSelectDelete(t *testing.T) {
tape := bob.Tape{
Cell: []bob.Cell{
{S: Prefix},
{S: SELECT},
{S: Select},
{S: "a9a4387d2baa2edcc53ec040b3affbc38778e9dd876f9a47e5c767c785aacf76"},
{S: DELETE},
{S: Delete},
{S: "keyName1"},
{S: "something"},
},
}
m := MAP{}
m.FromTape(tape)
if m[CMD] != SELECT || m["key"] != "keyName1" || m["value"] != "something" {
t.Errorf("SELECT + DELETE Failed %s %+v", m[CMD], m)
m.FromTape(&tape)
if m[Cmd] != Select || m["key"] != "keyName1" || m["value"] != "something" {
t.Errorf("SELECT + DELETE Failed %s %+v", m[Cmd], m)
}
}

func TestAdd(t *testing.T) {
tape := bob.Tape{
Cell: []bob.Cell{
{S: Prefix},
{S: ADD},
{S: Add},
{S: "keyName"},
{S: "something"},
{S: "something else"},
},
}
m := MAP{}
m.FromTape(tape)
m.FromTape(&tape)

switch m["keyName"].(type) {
case []string:
Expand All @@ -62,13 +62,13 @@ func TestDelete(t *testing.T) {
tape := bob.Tape{
Cell: []bob.Cell{
{S: Prefix},
{S: DELETE},
{S: Delete},
{S: "keyName"},
{S: "something"},
},
}
m := MAP{}
m.FromTape(tape)
m.FromTape(&tape)

if m["key"] != "keyName" || m["value"] != "something" {
t.Errorf("DELETE Failed %s %s", m["key"], m["value"])
Expand All @@ -80,15 +80,15 @@ func TestSet(t *testing.T) {
tape := bob.Tape{
Cell: []bob.Cell{
{S: Prefix},
{S: SET},
{S: Set},
{S: "keyName1"},
{S: "something"},
{S: "keyName2"},
{S: "something else"},
},
}
m := MAP{}
m.FromTape(tape)
m.FromTape(&tape)
if m["keyName1"] != "something" {
t.Errorf("SET Failed %s", m["keyName1"])
}
Expand All @@ -98,12 +98,12 @@ func TestRemove(t *testing.T) {
tape := bob.Tape{
Cell: []bob.Cell{
{S: Prefix},
{S: REMOVE},
{S: Remove},
{S: "keyName1"},
},
}
m := MAP{}
m.FromTape(tape)
m.FromTape(&tape)
if m["key"] != "keyName1" {
t.Errorf("REMOVE Failed %s", m["key"])
}
Expand Down

0 comments on commit 27be41e

Please sign in to comment.