You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by cm...@apache.org on 2019/10/09 12:49:14 UTC

[incubator-milagro-dta] 04/06: Update fishhook

This is an automated email from the ASF dual-hosted git repository.

cmorris pushed a commit to branch tendermint
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git

commit 7e811ee9389319b58ac94b02a3bd1242e858c5d7
Author: Christopher Morris <ch...@morris.net>
AuthorDate: Wed Oct 9 11:09:54 2019 +0100

    Update fishhook
---
 go.sum                                    |   9 ++
 p                                         |   4 +-
 pkg/endpoints/endpoints.go                |   2 +-
 pkg/tendermint/cmd/fishhook.go            | 111 -------------------
 pkg/tendermint/fishhook/build             |   2 +
 pkg/tendermint/{cmd => fishhook}/fishhook | Bin 24169060 -> 29288396 bytes
 pkg/tendermint/fishhook/main.go           | 173 ++++++++++++++++++++++++++++++
 pkg/tendermint/fishhook/run               |   2 +
 8 files changed, 189 insertions(+), 114 deletions(-)

diff --git a/go.sum b/go.sum
index 46b42dc..58723e7 100644
--- a/go.sum
+++ b/go.sum
@@ -61,6 +61,7 @@ github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3yg
 github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
 github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
+github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
 github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
 github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
 github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
@@ -122,10 +123,14 @@ github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg
 github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
+github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5 h1:l16XLUUJ34wIz+RIvLhSwGvLvKyy+W598b135bJN6mg=
 github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
 github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
 github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
+github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik=
 github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/mwitkow/go-proto-validators v0.1.0 h1:2Org0/cGKUUUDzoLSRSsGJDqyLWrb5lG57o5+QdRr8M=
@@ -138,6 +143,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
 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=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
 github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
@@ -170,6 +176,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
 github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4=
 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
+github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
 github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
@@ -181,6 +188,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/stumble/gorocksdb v0.0.3/go.mod h1:v6IHdFBXk5DJ1K4FZ0xi+eY737quiiBxYtSWXadLybY=
 github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw=
@@ -269,6 +277,7 @@ gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
 gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/p b/p
index 4d94421..320be46 100755
--- a/p
+++ b/p
@@ -1,6 +1,6 @@
 #!/bin/bash
-export ref=$(curl -s -X POST "127.0.0.1:5556/v1/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}")
+export ref=$(curl -s -X POST "127.0.0.1:5556/v1/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}")
 sleep 4
-curl -X POST "127.0.0.1:5556/v1/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":\"$1\"}"
+curl -X POST "127.0.0.1:5556/v1/order/secret" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":\"$1\"}"
 
 
diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go
index e046d83..1465c56 100644
--- a/pkg/endpoints/endpoints.go
+++ b/pkg/endpoints/endpoints.go
@@ -238,7 +238,7 @@ func MakeStatusEndpoint(m service.Service, log *logger.Logger, nodeType string)
 
 func validateRequest(req interface{}) error {
 	validate := validator.New()
-	validate.RegisterAlias("hashID", "min=40,max=64")
+	validate.RegisterAlias("hashID", "min=0,max=64")
 	if err := validate.Struct(req); err != nil {
 		return errors.Wrap(transport.ErrInvalidRequest, err.Error())
 	}
diff --git a/pkg/tendermint/cmd/fishhook.go b/pkg/tendermint/cmd/fishhook.go
deleted file mode 100644
index b3344a1..0000000
--- a/pkg/tendermint/cmd/fishhook.go
+++ /dev/null
@@ -1,111 +0,0 @@
-package main
-
-import (
-	"encoding/base64"
-	"encoding/hex"
-	"encoding/json"
-	"fmt"
-	"io/ioutil"
-	"log"
-	"net/http"
-	"os"
-	"time"
-
-	"github.com/TylerBrock/colorjson"
-	"github.com/apache/incubator-milagro-dta/pkg/tendermint"
-	"github.com/urfave/cli"
-)
-
-func main() {
-	app := cli.NewApp()
-	app.Name = "tmget"
-	app.Version = "0.1.0"
-	app.Compiled = time.Now()
-	app.Authors = []cli.Author{
-		cli.Author{
-			Name:  "Chris Morris",
-			Email: "chris@morris.net",
-		},
-	}
-	app.Copyright = "(c) 2019 Chris Morris"
-	app.UsageText = `tmget tag search [url]
-eg. tmget tag.recipient=Nzw3127EaxPiiZahOH592sGhPnCPaYkzOSqEk 127.0.0.1:5556
-    tmget tx Nzw3127EaxPiiZahOH592sGhPnCPaYkzOSqEk`
-
-	app.Usage = `retrieve and parse a transaction in the Qredo DT-A Format from a Tendermint Blockchain
-Note tags are case sensistive
-Qredo DT-A uses:
-  tag.recipient
-  tag.senderid
-  tag.reference
-  tx
-
-`
-
-	app.ArgsUsage = "tx"
-
-	app.Action = func(c *cli.Context) error {
-		tag := c.Args().Get(0)
-		lookup := "'" + c.Args().Get(1) + "'"
-
-		url := c.Args().Get(2)
-		//curl "localhost:26657/tx_search?query=\"tag.name='matts'\"&prove=true"
-		if url == "" {
-			url = "localhost:26657"
-		}
-		// if len(c.Args()) == 0 {
-		// 	print(app.UsageText)
-		// 	return nil
-		// }
-
-		fullUrl := "http://" + url + "/tx_search?query=\"" + tag + "=" + lookup + "\""
-		print(fullUrl)
-
-		resp, err := http.Get(fullUrl)
-		if err != nil {
-			// handle error
-		}
-		defer resp.Body.Close()
-		body, err := ioutil.ReadAll(resp.Body)
-
-		txResponse, err := tendermint.UnmarshalFetchTxResponse([]byte(body))
-
-		txs := txResponse.TResult.Txs
-		for r1, v := range txs {
-			for r2, v1 := range v.TxResult.Events {
-				for r3, v2 := range v1.Attributes {
-					newkey, _ := base64.StdEncoding.DecodeString(v2.Key)
-					txResponse.TResult.Txs[r1].TxResult.Events[r2].Attributes[r3].Key = string(newkey)
-					newval, _ := base64.StdEncoding.DecodeString(v2.Value)
-					txResponse.TResult.Txs[r1].TxResult.Events[r2].Attributes[r3].Value = string(newval)
-
-					if string(newkey) == "key" {
-						txResponse.TResult.Txs[r1].TxResult.Events[r2].Attributes[r3].Value = hex.EncodeToString(newval)
-					}
-				}
-			}
-		}
-
-		x, err := txResponse.Marshal()
-
-		var obj map[string]interface{}
-		json.Unmarshal(x, &obj)
-
-		//print(string(x))
-
-		// Make a custom formatter with indent set
-		f := colorjson.NewFormatter()
-		f.Indent = 4
-
-		// Marshall the Colorized JSON
-		s, _ := f.Marshal(obj)
-		fmt.Println(string(s))
-
-		return nil
-	}
-
-	err := app.Run(os.Args)
-	if err != nil {
-		log.Fatal(err)
-	}
-}
diff --git a/pkg/tendermint/fishhook/build b/pkg/tendermint/fishhook/build
new file mode 100755
index 0000000..f590499
--- /dev/null
+++ b/pkg/tendermint/fishhook/build
@@ -0,0 +1,2 @@
+go build -o fishhook main.go
+
diff --git a/pkg/tendermint/cmd/fishhook b/pkg/tendermint/fishhook/fishhook
similarity index 67%
rename from pkg/tendermint/cmd/fishhook
rename to pkg/tendermint/fishhook/fishhook
index 854a652..be3a244 100755
Binary files a/pkg/tendermint/cmd/fishhook and b/pkg/tendermint/fishhook/fishhook differ
diff --git a/pkg/tendermint/fishhook/main.go b/pkg/tendermint/fishhook/main.go
new file mode 100644
index 0000000..3f4dd4c
--- /dev/null
+++ b/pkg/tendermint/fishhook/main.go
@@ -0,0 +1,173 @@
+package main
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"log"
+	"os"
+	"path/filepath"
+	"strconv"
+	"time"
+
+	"github.com/apache/incubator-milagro-dta/libs/documents"
+	"github.com/apache/incubator-milagro-dta/libs/keystore"
+	"github.com/apache/incubator-milagro-dta/pkg/api"
+	"github.com/apache/incubator-milagro-dta/pkg/config"
+	"github.com/apache/incubator-milagro-dta/pkg/identity"
+	"github.com/hokaccha/go-prettyjson"
+	tmclient "github.com/tendermint/tendermint/rpc/client"
+	tmtypes "github.com/tendermint/tendermint/types"
+	"github.com/urfave/cli"
+)
+
+const (
+	envMilagroHome = "MILAGRO_HOME"
+	keysFile       = "keys"
+
+	cmdInit   = "init"
+	cmdDaemon = "daemon"
+)
+
+func main() {
+	app := cli.NewApp()
+	app.Name = "tmget"
+	app.Version = "0.1.0"
+	app.Compiled = time.Now()
+	app.Authors = []cli.Author{
+		cli.Author{
+			Name:  "Chris Morris",
+			Email: "chris@morris.net",
+		},
+	}
+	app.Copyright = "(c) 2019 Chris Morris"
+	app.UsageText = `fishhook configdir nodeurl query skip
+eg. fishhook /Users/john/.milagro 10.10,10,10:26657 "tag.recipient='Au1WipqVeTx9i2PV4UcCxmY6iQvA9RZXy88xJLRzafwc'" 3
+
+configdir - the local directory where the DT-A configuration (eg. config.yaml, keys) are stored
+nodeurl   - the host:port of a member Node of the Tendermint Network
+query     - A query to filter the results by (enclosed query in double quotes and values in single quotes)
+skip      - number of matches to skip before showing match and terminating
+`
+	app.Usage = `retrieve and parse a transaction in the Qredo DT-A Format from a Tendermint Blockchain
+Note tags are case sensistive
+`
+
+	app.Action = func(c *cli.Context) error {
+		folder := c.Args().Get(0)
+		host := c.Args().Get(1)
+		query := c.Args().Get(2)
+		skip, err := strconv.Atoi(c.Args().Get(3))
+
+		if err != nil {
+			print("Invalid skip value\n")
+			os.Exit(1)
+		}
+
+		if len(c.Args()) != 4 {
+			print(app.UsageText)
+			os.Exit(1)
+			return nil
+		}
+
+		cfg, err := parseConfig(folder)
+		if err != nil {
+			print("Failed to open config")
+			os.Exit(1)
+		}
+
+		keyStore, err := keystore.NewFileStore(filepath.Join(folder, keysFile))
+		if err != nil {
+			print("Fail to open keystore")
+			os.Exit(1)
+		}
+
+		keyseed, err := keyStore.Get("seed")
+		if err != nil {
+			print("Fail to retrieve keyseed")
+			os.Exit(1)
+		}
+
+		_, sikeSK, err := identity.GenerateSIKEKeys(keyseed)
+		if err != nil {
+			print("Fail to retrieve sikeSK")
+			os.Exit(1)
+		}
+		blsPk, _, err := identity.GenerateBLSKeys(keyseed)
+		if err != nil {
+			print("Fail to retrieve blsSK")
+			os.Exit(1)
+		}
+
+		//connect to Node
+		tmClient := tmclient.NewHTTP(fmt.Sprintf("tcp://%s", host), "/websocket")
+		if err := tmClient.Start(); err != nil {
+			print("Failed to open websocket")
+			os.Exit(1)
+		}
+
+		out, err := tmClient.Subscribe(context.Background(), "", query, 1000)
+		if err != nil {
+			print("Failed to subscribe to node")
+			os.Exit(1)
+		}
+
+		matchCount := 0
+		for {
+			select {
+			case result := <-out:
+				matchCount++
+				if matchCount != skip {
+					continue
+				}
+
+				print("result")
+				tx := result.Data.(tmtypes.EventDataTx).Tx
+				nodeID := cfg.Node.NodeID
+				payload := &api.BlockChainTX{}
+				err := json.Unmarshal(tx, payload)
+				if err != nil {
+					print("Invalid Transaction received")
+					os.Exit(1)
+				}
+
+				//dump
+				order := &documents.OrderDoc{}
+				err = documents.DecodeOrderDocument(payload.Payload, "", order, sikeSK, nodeID, blsPk)
+
+				pp, _ := prettyjson.Marshal(order)
+				fmt.Println(string(pp))
+				os.Exit(0)
+			}
+		}
+	}
+
+	err := app.Run(os.Args)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func getEnv(name, defaultValue string) string {
+	v, ok := os.LookupEnv(name)
+	if !ok {
+		return defaultValue
+	}
+
+	return v
+}
+
+func parseConfig(folder string) (*config.Config, error) {
+	cfg, err := config.ParseConfig(folder)
+	if err != nil {
+		return nil, err
+	}
+	return cfg, nil
+}
+
+//Use - helper to remove warnings
+func Use(vals ...interface{}) {
+	for _, val := range vals {
+		_ = val
+	}
+}
diff --git a/pkg/tendermint/fishhook/run b/pkg/tendermint/fishhook/run
new file mode 100755
index 0000000..1e44661
--- /dev/null
+++ b/pkg/tendermint/fishhook/run
@@ -0,0 +1,2 @@
+./fishhook /Users/chris/.milagro 34.246.173.153:26657 "tag.recipient='Au1WipqVeTx9i2PV4UcCxmY6iQvA9RZXy88xJLRzafwc'" 1
+