You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sm...@apache.org on 2019/10/08 11:05:20 UTC
[incubator-milagro-dta] branch tendermint updated: Use base58
encoding for tx IDs
This is an automated email from the ASF dual-hosted git repository.
smihaylov pushed a commit to branch tendermint
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git
The following commit(s) were added to refs/heads/tendermint by this push:
new 1e924d6 Use base58 encoding for tx IDs
1e924d6 is described below
commit 1e924d6ed64a9e4f822d0b173e4bb79f78bee57c
Author: Stanislav Mihaylov <sm...@gmail.com>
AuthorDate: Tue Oct 8 14:04:14 2019 +0300
Use base58 encoding for tx IDs
Refactor BlockChain TX and order creation
---
cmd/servicetester/tendertest1.sh | 4 ++--
go.mod | 1 +
go.sum | 5 +++++
pkg/api/proto.go | 43 ++++++++++++++++++++++++++++++++++------
pkg/common/chain.go | 32 +++++++++++++++++++-----------
pkg/common/common.go | 4 ++--
pkg/defaultservice/fulfillTX.go | 32 ++++++------------------------
pkg/defaultservice/order.go | 36 ++++++++-------------------------
pkg/defaultservice/orderTX.go | 32 ++++++++----------------------
pkg/endpoints/endpoints.go | 2 +-
pkg/identity/identity.go | 19 ++++--------------
pkg/tendermint/connector.go | 9 ++++++---
12 files changed, 100 insertions(+), 119 deletions(-)
diff --git a/cmd/servicetester/tendertest1.sh b/cmd/servicetester/tendertest1.sh
index 318f1e9..cffef3a 100755
--- a/cmd/servicetester/tendertest1.sh
+++ b/cmd/servicetester/tendertest1.sh
@@ -1,8 +1,8 @@
-ref=$(curl -s -X POST "127.0.0.1:5556/v1/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"90bac919210be1ef29cd6da22d512c2f8a04693544fe6e474cb5d90c6fbe4645\",\"extension\":{\"coin\":\"0\"}}")
+ref=$(curl -s -X POST "127.0.0.1:5556/v1/order1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"8zxdWSXs6dDYpqbNrGQsH2kBWPVgcj9WhanddrCzHZjk\",\"extension\":{\"coin\":\"0\"}}")
#sleep long enough for blockchain to catch up
sleep 4
-curl -X POST "127.0.0.1:5556/v1/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":\"90bac919210be1ef29cd6da22d512c2f8a04693544fe6e474cb5d90c6fbe4645\"}"
+curl -X POST "127.0.0.1:5556/v1/order/secret1" -H "accept: */*" -H "Content-Type: application/json" -d "{\"orderReference\":$ref,\"beneficiaryIDDocumentCID\":\"8zxdWSXs6dDYpqbNrGQsH2kBWPVgcj9WhanddrCzHZjk\"}"
diff --git a/go.mod b/go.mod
index 384d062..dd70335 100644
--- a/go.mod
+++ b/go.mod
@@ -24,6 +24,7 @@ require (
github.com/pkg/errors v0.8.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v0.9.3
+ github.com/rs/zerolog v1.15.0
github.com/stretchr/testify v1.4.0
github.com/stumble/gorocksdb v0.0.3 // indirect
github.com/tendermint/tendermint v0.32.4
diff --git a/go.sum b/go.sum
index b36c254..2dc56bc 100644
--- a/go.sum
+++ b/go.sum
@@ -157,6 +157,9 @@ github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqn
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
+github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
+github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
+github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
@@ -191,6 +194,7 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
+github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -236,6 +240,7 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
diff --git a/pkg/api/proto.go b/pkg/api/proto.go
index 59f1d77..57209a8 100644
--- a/pkg/api/proto.go
+++ b/pkg/api/proto.go
@@ -25,8 +25,9 @@ package api
import (
"crypto/sha256"
- "encoding/hex"
"time"
+
+ "github.com/btcsuite/btcutil/base58"
)
const (
@@ -46,6 +47,8 @@ const (
TXFulfillOrderSecretRequest = "v1/fulfill/order/secret"
// TXFulfillOrderSecretResponse -
TXFulfillOrderSecretResponse = "v1/order/secret2"
+ // TXIdentity - Identity document
+ TXIdentity = "v1/identity"
// TXOrderSecretResponse -
TXOrderSecretResponse = "dump"
)
@@ -61,16 +64,44 @@ type BlockChainTX struct {
Tags map[string]string
}
-// CalcHash calculates, sets the TXhash and returns the string representation
+// NewBlockChainTX constructs a new Tx and returns it with the TxID
+func NewBlockChainTX(processor string, payload []byte, ref string, senderID string, recipients ...string) (*BlockChainTX, string) {
+ b := &BlockChainTX{
+ Processor: processor,
+ Payload: payload,
+ SenderID: senderID,
+ Tags: make(map[string]string),
+ }
+ // Add recipients
+ for i, r := range recipients {
+ if i == 0 {
+ b.RecipientID = r
+ continue
+ }
+ b.AdditionalRecipientIDs = append(b.AdditionalRecipientIDs, r)
+ }
+ // Add reference tag
+ if ref != "" {
+ b.Tags["reference"] = ref
+ }
+ // Calculate hash
+ txHash := b.CalcHash()
+ // Set the hash tag
+ b.Tags["txhash"] = txHash
+
+ return b, txHash
+}
+
+// CalcHash calculates, sets the TXhash and returns the string representation using Base58 encoding
func (tx *BlockChainTX) CalcHash() string {
txSha := sha256.Sum256(tx.Payload)
- txHash := hex.EncodeToString(txSha[:])
+ txHash := base58.Encode(txSha[:])
- tx.TXhash = txSha[:]
- tx.Tags["txhash"] = txHash
+ // txHash := hex.EncodeToString(txSha[:])
+ // tx.TXhash = txSha[:]
+ // tx.Tags["txhash"] = txHash
return txHash
-
}
//CreateIdentityRequest -
diff --git a/pkg/common/chain.go b/pkg/common/chain.go
index 8608bed..43b5dbc 100644
--- a/pkg/common/chain.go
+++ b/pkg/common/chain.go
@@ -1,27 +1,35 @@
package common
import (
- "crypto/sha256"
- "encoding/hex"
-
"github.com/apache/incubator-milagro-dta/libs/datastore"
"github.com/apache/incubator-milagro-dta/libs/documents"
+ "github.com/apache/incubator-milagro-dta/pkg/api"
"github.com/pkg/errors"
)
-// CreateTX creates the transaction ready for write to the chain
-func CreateTX(nodeID string, store *datastore.Store, blsSecretKey []byte, id string, order *documents.OrderDoc, recipients map[string]*documents.IDDoc) ([]byte, []byte, error) {
- rawDoc, err := documents.EncodeOrderDocument(nodeID, *order, blsSecretKey, recipients)
+// CreateOrderTX creates the transaction ready for write to the chain
+func CreateOrderTX(
+ nodeID string,
+ processor string,
+ store *datastore.Store,
+ blsSecretKey []byte,
+ order *documents.OrderDoc,
+ recipientDocs map[string]*documents.IDDoc,
+ recipientID string,
+) (*api.BlockChainTX, string, error) {
+ rawDoc, err := documents.EncodeOrderDocument(nodeID, *order, blsSecretKey, recipientDocs)
if err != nil {
- return nil, nil, errors.Wrap(err, "Failed to encode IDDocument")
+ return nil, "", errors.Wrap(err, "Failed to encode IDDocument")
}
- TXID := sha256.Sum256(rawDoc)
- TXIDhex := hex.EncodeToString(TXID[:])
+
+ tx, txID := api.NewBlockChainTX(processor, rawDoc, order.Reference, nodeID, recipientID)
+
//Write order to store
- if err := WriteOrderToStore(store, order.Reference, TXIDhex); err != nil {
- return nil, nil, errors.New("Save Order to store")
+ if err := WriteOrderToStore(store, order.Reference, txID); err != nil {
+ return nil, "", errors.New("Save Order to store")
}
- return TXID[:], rawDoc, nil
+
+ return tx, txID, nil
}
//PeekTX Decode a transaction for header data but don't decrypt it
diff --git a/pkg/common/common.go b/pkg/common/common.go
index f3a88fd..52c7d0e 100644
--- a/pkg/common/common.go
+++ b/pkg/common/common.go
@@ -34,7 +34,7 @@ import (
)
// CreateNewDepositOrder - Generate an empty new Deposit Order with random reference
-func CreateNewDepositOrder(BeneficiaryIDDocumentCID string, nodeID string) (*documents.OrderDoc, error) {
+func CreateNewDepositOrder(BeneficiaryIDDocumentCID string, nodeID string, orderType string) (*documents.OrderDoc, error) {
//Create a reference for this order
reference, err := uuid.NewUUID()
if err != nil {
@@ -49,7 +49,7 @@ func CreateNewDepositOrder(BeneficiaryIDDocumentCID string, nodeID string) (*doc
}
//oder.Type will be used to extend the things that an order can do.
- order.Type = "Safeguard_Secret"
+ order.Type = orderType
order.PrincipalCID = nodeID
order.Reference = reference.String()
order.BeneficiaryCID = BeneficiaryIDDocumentCID
diff --git a/pkg/defaultservice/fulfillTX.go b/pkg/defaultservice/fulfillTX.go
index c3bce0d..56eb773 100644
--- a/pkg/defaultservice/fulfillTX.go
+++ b/pkg/defaultservice/fulfillTX.go
@@ -93,20 +93,10 @@ func (s *Service) FulfillOrder(tx *api.BlockChainTX) (string, error) {
}
//Create a new Transaction payload and TX
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXFulfillResponse, s.Store, blsSK, order, recipientList, order.PrincipalCID)
+ s.Logger.Debug("Created new %v Tx: %v", api.TXFulfillResponse, txID)
- //Write the requests to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXFulfillResponse,
- SenderID: nodeID,
- RecipientID: order.PrincipalCID,
- AdditionalRecipientIDs: []string{},
- Payload: payload,
- TXhash: txHash,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
-
- return s.Tendermint.PostTx(chainTX, "FulfillOrder")
+ return s.Tendermint.PostTx(tx)
}
// FulfillOrderSecret -
@@ -174,18 +164,8 @@ func (s *Service) FulfillOrderSecret(tx *api.BlockChainTX) (string, error) {
}
//Create a new Transaction payload and TX
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
-
- //Write the requests to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXFulfillOrderSecretResponse,
- SenderID: nodeID,
- RecipientID: order.BeneficiaryCID,
- AdditionalRecipientIDs: []string{},
-
- Payload: payload,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXFulfillOrderSecretResponse, s.Store, blsSK, order, recipientList, order.BeneficiaryCID)
+ s.Logger.Debug("Created new %v Tx: %v", api.TXFulfillOrderSecretResponse, txID)
- return s.Tendermint.PostTx(chainTX, "FulfillOrderSecret")
+ return s.Tendermint.PostTx(tx)
}
diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go
index abc24ab..6ed4f5e 100644
--- a/pkg/defaultservice/order.go
+++ b/pkg/defaultservice/order.go
@@ -18,7 +18,6 @@
package defaultservice
import (
- "encoding/hex"
"time"
"github.com/apache/incubator-milagro-dta/libs/cryptowallet"
@@ -144,7 +143,7 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) {
}
//Create Order
- order, err := common.CreateNewDepositOrder(beneficiaryIDDocumentCID, nodeID)
+ order, err := common.CreateNewDepositOrder(beneficiaryIDDocumentCID, nodeID, s.Plugin.Name())
if err != nil {
return "", err
}
@@ -167,21 +166,11 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) {
return "", err
}
- //This is serialized and output to the chain
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
-
- //Write the requests to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXFulfillRequest,
- SenderID: nodeID,
- RecipientID: s.MasterFiduciaryNodeID(),
- AdditionalRecipientIDs: []string{},
- Payload: payload, //marshaledRequest,
- TXhash: txHash,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
+ //Create a new Transaction payload and TX
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXFulfillRequest, s.Store, blsSK, order, recipientList, s.MasterFiduciaryNodeID())
+ s.Logger.Debug("Created new %v Tx: %v", api.TXFulfillRequest, txID)
- if _, err := s.Tendermint.PostTx(chainTX, "Order1"); err != nil {
+ if _, err := s.Tendermint.PostTx(tx); err != nil {
return "", err
}
@@ -271,19 +260,10 @@ func (s *Service) OrderSecret1(req *api.OrderSecretRequest) (string, error) {
Timestamp: time.Now().Unix(),
}
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
-
- //Write the requests to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXFulfillOrderSecretRequest,
- SenderID: nodeID,
- RecipientID: s.MasterFiduciaryNodeID(),
- AdditionalRecipientIDs: []string{},
- Payload: payload,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXFulfillOrderSecretRequest, s.Store, blsSK, order, recipientList, s.MasterFiduciaryNodeID())
+ s.Logger.Debug("Created new %v Tx: %v", api.TXFulfillOrderSecretRequest, txID)
- if _, err := s.Tendermint.PostTx(chainTX, "OrderSecret1"); err != nil {
+ if _, err := s.Tendermint.PostTx(tx); err != nil {
return "", err
}
diff --git a/pkg/defaultservice/orderTX.go b/pkg/defaultservice/orderTX.go
index 19600ff..02ff5f5 100644
--- a/pkg/defaultservice/orderTX.go
+++ b/pkg/defaultservice/orderTX.go
@@ -82,20 +82,11 @@ func (s *Service) Order2(tx *api.BlockChainTX) (string, error) {
order.OrderPart2.Extension[key] = value
}
- //Generate a transaction
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
+ //Create a new Transaction payload and TX
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXOrderResponse, s.Store, blsSK, order, recipientList, nodeID)
+ s.Logger.Debug("Created new %v Tx: %v", api.TXOrderResponse, txID)
- //Write the Order2 results to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXOrderResponse,
- SenderID: nodeID,
- RecipientID: nodeID,
- AdditionalRecipientIDs: []string{},
- Payload: payload,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
-
- return s.Tendermint.PostTx(chainTX, "Order2")
+ return s.Tendermint.PostTx(tx)
}
// OrderSecret2 - Process an incoming Blockchain Order/Secret transaction from a MasterFiduciary, to generate the final secret
@@ -158,17 +149,10 @@ func (s *Service) OrderSecret2(tx *api.BlockChainTX) (string, error) {
if err != nil {
return "", err
}
- txHash, payload, err := common.CreateTX(nodeID, s.Store, blsSK, nodeID, order, recipientList)
- //Write the requests to the chain
- chainTX := &api.BlockChainTX{
- Processor: api.TXOrderSecretResponse, //NONE
- SenderID: nodeID,
- RecipientID: nodeID,
- AdditionalRecipientIDs: []string{},
- Payload: payload,
- Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)},
- }
+ //Create a new Transaction payload and TX
+ tx, txID, err := common.CreateOrderTX(nodeID, api.TXOrderSecretResponse, s.Store, blsSK, order, recipientList, nodeID)
+ s.Logger.Debug("Created new %v Tx: %v", api.TXOrderSecretResponse, txID)
- return s.Tendermint.PostTx(chainTX, "OrderSecret2")
+ return s.Tendermint.PostTx(tx)
}
diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go
index 6f767f6..237e3c2 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=64,max=64")
+ validate.RegisterAlias("hashID", "min=40,max=64")
if err := validate.Struct(req); err != nil {
return errors.Wrap(transport.ErrInvalidRequest, err.Error())
}
diff --git a/pkg/identity/identity.go b/pkg/identity/identity.go
index b6b236f..c02767e 100644
--- a/pkg/identity/identity.go
+++ b/pkg/identity/identity.go
@@ -24,13 +24,11 @@ import (
"bytes"
"time"
- "github.com/apache/incubator-milagro-dta/pkg/api"
-
- "github.com/apache/incubator-milagro-dta/pkg/tendermint"
-
"github.com/apache/incubator-milagro-dta/libs/cryptowallet"
"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/tendermint"
"github.com/pkg/errors"
)
@@ -80,18 +78,9 @@ func CreateIdentity(name string) (idDocument *documents.IDDoc, rawIDDoc, seed []
// StoreIdentity writes IDDocument to blockchain and secret to keystore
func StoreIdentity(rawIDDoc, secret []byte, tmConn *tendermint.NodeConnector, store keystore.Store) (idDocumentID string, err error) {
- chainTX := &api.BlockChainTX{
- Processor: api.TXFulfillOrderSecretRequest,
- SenderID: tmConn.NodeID(),
- RecipientID: "",
- AdditionalRecipientIDs: []string{},
- Payload: rawIDDoc,
- Tags: map[string]string{},
- }
-
- idDocumentID = chainTX.CalcHash()
+ chainTx, idDocumentID := api.NewBlockChainTX(api.TXIdentity, rawIDDoc, "", tmConn.NodeID())
- if _, err := tmConn.PostTx(chainTX, "IDDocument"); err != nil {
+ if _, err := tmConn.PostTx(chainTx); err != nil {
return "", err
}
diff --git a/pkg/tendermint/connector.go b/pkg/tendermint/connector.go
index 1852f79..bf2f7e7 100644
--- a/pkg/tendermint/connector.go
+++ b/pkg/tendermint/connector.go
@@ -95,7 +95,7 @@ func (nc *NodeConnector) GetTx(txHash string) (*api.BlockChainTX, error) {
}
// PostTx posts a transaction to the chain and returns the transaction ID
-func (nc *NodeConnector) PostTx(tx *api.BlockChainTX, method string) (txID string, err error) {
+func (nc *NodeConnector) PostTx(tx *api.BlockChainTX) (txID string, err error) {
txID = tx.CalcHash()
//serialize the whole transaction
@@ -138,7 +138,7 @@ func (nc *NodeConnector) PostTx(tx *api.BlockChainTX, method string) (txID strin
return "", errors.Errorf("Post to blockchain node status %v: %v", resp.StatusCode, respErr)
}
- nc.log.Debug("POST TO CHAIN: METHOD: %s CALLS: %s - TXID: %s", method, tx.Processor, txID)
+ nc.log.Debug("Post to chain: Processor: %s: txID: %s", tx.Processor, txID)
return
}
@@ -181,7 +181,7 @@ func (nc *NodeConnector) Subscribe(ctx context.Context, processFn ProcessTXFunc)
func (nc *NodeConnector) subscribeAndQueue(ctx context.Context, txQueue chan *api.BlockChainTX) error {
query := "tag.recipient='" + nc.nodeID + "'"
- out, err := nc.tmClient.Subscribe(context.Background(), "test", query, 1000)
+ out, err := nc.tmClient.Subscribe(context.Background(), "", query, 1000)
if err != nil {
return errors.Wrapf(err, "Failed to subscribe to query %s", query)
}
@@ -192,6 +192,7 @@ func (nc *NodeConnector) subscribeAndQueue(ctx context.Context, txQueue chan *ap
case result := <-out:
tx := result.Data.(tmtypes.EventDataTx).Tx
payload := &api.BlockChainTX{}
+
err := json.Unmarshal(tx, payload)
if err != nil {
nc.log.Debug("IGNORED TX - Invalid!")
@@ -204,6 +205,8 @@ func (nc *NodeConnector) subscribeAndQueue(ctx context.Context, txQueue chan *ap
break
}
+ // TODO: Check if hash match the payload
+
//Add into the waitingQueue for later processing
txQueue <- payload
case <-ctx.Done():