Repository: hyperledger/firefly (go)

Issue:
Blockchain Events from a Contract Listener do not populate blockchain transaction ID
<img width="1525" alt="FireFly_Explorer" src="https://user-images.githubusercontent.com/1993829/165160879-b544c948-62ff-4de2-95bb-ad323ea9837f.png">

Pull request description:
Fill in blockchain TX ID for contract listener events
Fixes #761

Patch:
diff --git a/docs/_config.yml b/docs/_config.yml
index c31b1bfe4..1194179b7 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -8,8 +8,8 @@ aux_links:
     - "//github.com/hyperledger/firefly"
   "Wiki":
     - "https://wiki.hyperledger.org/display/FIR"
-  "Discord":
-    - "https://discord.gg/hyperledger"
+  "Chat":
+    - "https://chat.hyperledger.org/channel/firefly"
   "Mailing List":
     - "https://lists.hyperledger.org/g/firefly"
   "Calendar":
diff --git a/docs/faqs/faqs.md b/docs/faqs/faqs.md
index a5ec3c20f..205896247 100644
--- a/docs/faqs/faqs.md
+++ b/docs/faqs/faqs.md
@@ -9,6 +9,6 @@ has_children: true
 
 Find answers to the most commonly asked FireFly questions.
 
-This content is coming soon and will be guided by community interactions via Discord, meetups, webinars and other technical forums.
+This content is coming soon and will be guided by community interactions via RocketChat, meetups, webinars and other technical forums.
 
-If you have immediate questions please don't hesitate to reach out to us on the [Hyperledger Discord](https://discord.gg/hyperledger) in the `#firefly` channel.
+If you have immediate questions please don't hesitate to reach out to us on our [FireFly RocketChat Channel](https://chat.hyperledger.org/channel/firefly).
diff --git a/internal/blockchain/ethereum/config.go b/internal/blockchain/ethereum/config.go
index 47e57f6df..e42297fac 100644
--- a/internal/blockchain/ethereum/config.go
+++ b/internal/blockchain/ethereum/config.go
@@ -17,9 +17,9 @@
 package ethereum
 
 import (
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/pkg/config"
 	"github.com/hyperledger/firefly/pkg/ffresty"
-	"github.com/hyperledger/firefly/pkg/wsclient"
 )
 
 const (
@@ -71,7 +71,7 @@ const (
 
 func (e *Ethereum) InitPrefix(prefix config.Prefix) {
 	ethconnectConf := prefix.SubPrefix(EthconnectConfigKey)
-	wsclient.InitPrefix(ethconnectConf)
+	wsconfig.InitPrefix(ethconnectConf)
 	ethconnectConf.AddKnownKey(EthconnectConfigInstancePath)
 	ethconnectConf.AddKnownKey(EthconnectConfigTopic)
 	ethconnectConf.AddKnownKey(EthconnectConfigBatchSize, defaultBatchSize)
diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go
index 73f335372..26f75ab77 100644
--- a/internal/blockchain/ethereum/ethereum.go
+++ b/internal/blockchain/ethereum/ethereum.go
@@ -25,6 +25,7 @@ import (
 	"strings"
 
 	"github.com/go-resty/resty/v2"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/internal/coremsgs"
 	"github.com/hyperledger/firefly/internal/metrics"
 	"github.com/hyperledger/firefly/pkg/blockchain"
@@ -206,7 +207,7 @@ func (e *Ethereum) Init(ctx context.Context, prefix config.Prefix, callbacks blo
 	e.prefixShort = ethconnectConf.GetString(EthconnectPrefixShort)
 	e.prefixLong = ethconnectConf.GetString(EthconnectPrefixLong)
 
-	wsConfig := wsclient.GenerateConfigFromPrefix(ethconnectConf)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(ethconnectConf)
 
 	if wsConfig.WSKeyPath == "" {
 		wsConfig.WSKeyPath = "/ws"
diff --git a/internal/blockchain/fabric/config.go b/internal/blockchain/fabric/config.go
index 21c655d81..541bbcfb4 100644
--- a/internal/blockchain/fabric/config.go
+++ b/internal/blockchain/fabric/config.go
@@ -17,8 +17,8 @@
 package fabric
 
 import (
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/pkg/config"
-	"github.com/hyperledger/firefly/pkg/wsclient"
 )
 
 const (
@@ -53,7 +53,7 @@ const (
 
 func (f *Fabric) InitPrefix(prefix config.Prefix) {
 	fabconnectConf := prefix.SubPrefix(FabconnectConfigKey)
-	wsclient.InitPrefix(fabconnectConf)
+	wsconfig.InitPrefix(fabconnectConf)
 	fabconnectConf.AddKnownKey(FabconnectConfigDefaultChannel)
 	fabconnectConf.AddKnownKey(FabconnectConfigChaincode)
 	fabconnectConf.AddKnownKey(FabconnectConfigSigner)
diff --git a/internal/blockchain/fabric/fabric.go b/internal/blockchain/fabric/fabric.go
index 60d06ad1c..55a6a5bda 100644
--- a/internal/blockchain/fabric/fabric.go
+++ b/internal/blockchain/fabric/fabric.go
@@ -27,6 +27,7 @@ import (
 	"strings"
 
 	"github.com/go-resty/resty/v2"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/internal/coremsgs"
 	"github.com/hyperledger/firefly/internal/metrics"
 	"github.com/hyperledger/firefly/pkg/blockchain"
@@ -190,7 +191,7 @@ func (f *Fabric) Init(ctx context.Context, prefix config.Prefix, callbacks block
 		GlobalSequencer: true,
 	}
 
-	wsConfig := wsclient.GenerateConfigFromPrefix(fabconnectConf)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(fabconnectConf)
 
 	if wsConfig.WSKeyPath == "" {
 		wsConfig.WSKeyPath = "/ws"
diff --git a/pkg/wsclient/wsconfig.go b/internal/coreconfig/wsconfig/wsconfig.go
similarity index 95%
rename from pkg/wsclient/wsconfig.go
rename to internal/coreconfig/wsconfig/wsconfig.go
index c9936f6c0..9c202437c 100644
--- a/pkg/wsclient/wsconfig.go
+++ b/internal/coreconfig/wsconfig/wsconfig.go
@@ -14,11 +14,12 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package wsclient
+package wsconfig
 
 import (
 	"github.com/hyperledger/firefly/pkg/config"
 	"github.com/hyperledger/firefly/pkg/ffresty"
+	"github.com/hyperledger/firefly/pkg/wsclient"
 )
 
 const (
@@ -53,8 +54,8 @@ func InitPrefix(prefix config.KeySet) {
 	prefix.AddKnownKey(WSConfigHeartbeatInterval, defaultHeartbeatInterval)
 }
 
-func GenerateConfigFromPrefix(prefix config.Prefix) *WSConfig {
-	return &WSConfig{
+func GenerateConfigFromPrefix(prefix config.Prefix) *wsclient.WSConfig {
+	return &wsclient.WSConfig{
 		HTTPURL:                prefix.GetString(ffresty.HTTPConfigURL),
 		WSKeyPath:              prefix.GetString(WSConfigKeyPath),
 		ReadBufferSize:         int(prefix.GetByteSize(WSConfigKeyReadBufferSize)),
diff --git a/internal/database/sqlcommon/tokenapproval_sql.go b/internal/database/sqlcommon/tokenapproval_sql.go
index e681c1917..5c34e1a58 100644
--- a/internal/database/sqlcommon/tokenapproval_sql.go
+++ b/internal/database/sqlcommon/tokenapproval_sql.go
@@ -195,7 +195,7 @@ func (s *SQLCommon) GetTokenApprovalByProtocolID(ctx context.Context, poolID *ff
 	})
 }
 
-func (s *SQLCommon) GetTokenApprovals(ctx context.Context, filter database.Filter) ([]*fftypes.TokenApproval, *database.FilterResult, error) {
+func (s *SQLCommon) GetTokenApprovals(ctx context.Context, filter database.Filter) (approvals []*fftypes.TokenApproval, fr *database.FilterResult, err error) {
 	query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(tokenApprovalColumns...).From("tokenapproval"), filter, tokenApprovalFilterFieldMap, []interface{}{"seq"})
 	if err != nil {
 		return nil, nil, err
@@ -207,7 +207,6 @@ func (s *SQLCommon) GetTokenApprovals(ctx context.Context, filter database.Filte
 	}
 	defer rows.Close()
 
-	approvals := []*fftypes.TokenApproval{}
 	for rows.Next() {
 		d, err := s.tokenApprovalResult(ctx, rows)
 		if err != nil {
diff --git a/internal/database/sqlcommon/tokenpool_sql.go b/internal/database/sqlcommon/tokenpool_sql.go
index c15ed6bb6..29ef73006 100644
--- a/internal/database/sqlcommon/tokenpool_sql.go
+++ b/internal/database/sqlcommon/tokenpool_sql.go
@@ -201,7 +201,7 @@ func (s *SQLCommon) GetTokenPoolByLocator(ctx context.Context, connector, locato
 	})
 }
 
-func (s *SQLCommon) GetTokenPools(ctx context.Context, filter database.Filter) ([]*fftypes.TokenPool, *database.FilterResult, error) {
+func (s *SQLCommon) GetTokenPools(ctx context.Context, filter database.Filter) (message []*fftypes.TokenPool, fr *database.FilterResult, err error) {
 	query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(tokenPoolColumns...).From("tokenpool"), filter, tokenPoolFilterFieldMap, []interface{}{"seq"})
 	if err != nil {
 		return nil, nil, err
diff --git a/internal/dataexchange/ffdx/config.go b/internal/dataexchange/ffdx/config.go
index 14637d742..8b42b181f 100644
--- a/internal/dataexchange/ffdx/config.go
+++ b/internal/dataexchange/ffdx/config.go
@@ -17,8 +17,8 @@
 package ffdx
 
 import (
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/pkg/config"
-	"github.com/hyperledger/firefly/pkg/wsclient"
 )
 
 const (
@@ -29,7 +29,7 @@ const (
 )
 
 func (h *FFDX) InitPrefix(prefix config.Prefix) {
-	wsclient.InitPrefix(prefix)
+	wsconfig.InitPrefix(prefix)
 	prefix.AddKnownKey(DataExchangeManifestEnabled, false)
 	prefix.AddKnownKey(DataExchangeInitEnabled, false)
 }
diff --git a/internal/dataexchange/ffdx/ffdx.go b/internal/dataexchange/ffdx/ffdx.go
index 5d8e61818..780a94b98 100644
--- a/internal/dataexchange/ffdx/ffdx.go
+++ b/internal/dataexchange/ffdx/ffdx.go
@@ -26,6 +26,7 @@ import (
 	"sync"
 
 	"github.com/go-resty/resty/v2"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/internal/coremsgs"
 	"github.com/hyperledger/firefly/pkg/config"
 	"github.com/hyperledger/firefly/pkg/dataexchange"
@@ -126,7 +127,7 @@ func (h *FFDX) Init(ctx context.Context, prefix config.Prefix, nodes []fftypes.J
 		Manifest: prefix.GetBool(DataExchangeManifestEnabled),
 	}
 
-	wsConfig := wsclient.GenerateConfigFromPrefix(prefix)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(prefix)
 
 	h.wsconn, err = wsclient.New(ctx, wsConfig, h.beforeConnect, nil)
 	if err != nil {
diff --git a/internal/events/blockchain_event.go b/internal/events/blockchain_event.go
index fa8c43974..1a9346a5e 100644
--- a/internal/events/blockchain_event.go
+++ b/internal/events/blockchain_event.go
@@ -127,7 +127,9 @@ func (em *eventManager) BlockchainEvent(event *blockchain.EventWithSubscription)
 				return nil // no retry
 			}
 
-			chainEvent := buildBlockchainEvent(sub.Namespace, sub.ID, &event.Event, nil)
+			chainEvent := buildBlockchainEvent(sub.Namespace, sub.ID, &event.Event, &fftypes.BlockchainTransactionRef{
+				BlockchainID: event.BlockchainTXID,
+			})
 			if err := em.maybePersistBlockchainEvent(ctx, chainEvent); err != nil {
 				return err
 			}
diff --git a/internal/tokens/fftokens/config.go b/internal/tokens/fftokens/config.go
index d19540ee6..50ae74fef 100644
--- a/internal/tokens/fftokens/config.go
+++ b/internal/tokens/fftokens/config.go
@@ -17,10 +17,10 @@
 package fftokens
 
 import (
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/pkg/config"
-	"github.com/hyperledger/firefly/pkg/wsclient"
 )
 
 func (ft *FFTokens) InitPrefix(prefix config.PrefixArray) {
-	wsclient.InitPrefix(prefix)
+	wsconfig.InitPrefix(prefix)
 }
diff --git a/internal/tokens/fftokens/fftokens.go b/internal/tokens/fftokens/fftokens.go
index 7007d88bb..221dd96b1 100644
--- a/internal/tokens/fftokens/fftokens.go
+++ b/internal/tokens/fftokens/fftokens.go
@@ -21,6 +21,7 @@ import (
 	"encoding/json"
 
 	"github.com/go-resty/resty/v2"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/internal/coremsgs"
 	"github.com/hyperledger/firefly/pkg/blockchain"
 	"github.com/hyperledger/firefly/pkg/config"
@@ -143,7 +144,7 @@ func (ft *FFTokens) Init(ctx context.Context, name string, prefix config.Prefix,
 	ft.client = ffresty.New(ft.ctx, prefix)
 	ft.capabilities = &tokens.Capabilities{}
 
-	wsConfig := wsclient.GenerateConfigFromPrefix(prefix)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(prefix)
 
 	if wsConfig.WSKeyPath == "" {
 		wsConfig.WSKeyPath = "/api/ws"


Test patch:
diff --git a/internal/adminevents/manager_test.go b/internal/adminevents/manager_test.go
index 0d0660ecc..03d5f777d 100644
--- a/internal/adminevents/manager_test.go
+++ b/internal/adminevents/manager_test.go
@@ -27,6 +27,7 @@ import (
 	"time"
 
 	"github.com/hyperledger/firefly/internal/coreconfig"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/pkg/config"
 	"github.com/hyperledger/firefly/pkg/ffresty"
 	"github.com/hyperledger/firefly/pkg/fftypes"
@@ -41,9 +42,9 @@ func newTestAdminEventsManager(t *testing.T) (ae *adminEventManager, ws *webSock
 	svr := httptest.NewServer(http.HandlerFunc(ae.ServeHTTPWebSocketListener))
 
 	clientPrefix := config.NewPluginConfig("ut.wsclient")
-	wsclient.InitPrefix(clientPrefix)
+	wsconfig.InitPrefix(clientPrefix)
 	clientPrefix.Set(ffresty.HTTPConfigURL, fmt.Sprintf("http://%s", svr.Listener.Addr()))
-	wsConfig := wsclient.GenerateConfigFromPrefix(clientPrefix)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(clientPrefix)
 
 	wsc, err := wsclient.New(ae.ctx, wsConfig, nil, nil)
 	assert.NoError(t, err)
diff --git a/pkg/wsclient/wsconfig_test.go b/internal/coreconfig/wsconfig/wsconfig_test.go
similarity index 98%
rename from pkg/wsclient/wsconfig_test.go
rename to internal/coreconfig/wsconfig/wsconfig_test.go
index d8eef914b..65f72488f 100644
--- a/pkg/wsclient/wsconfig_test.go
+++ b/internal/coreconfig/wsconfig/wsconfig_test.go
@@ -1,4 +1,4 @@
-package wsclient
+package wsconfig
 
 import (
 	"testing"
diff --git a/internal/database/sqlcommon/tokenapproval_sql_test.go b/internal/database/sqlcommon/tokenapproval_sql_test.go
index 6588eeaa0..92b89270a 100644
--- a/internal/database/sqlcommon/tokenapproval_sql_test.go
+++ b/internal/database/sqlcommon/tokenapproval_sql_test.go
@@ -57,16 +57,9 @@ func TestApprovalE2EWithDB(t *testing.T) {
 	s.callbacks.On("UUIDCollectionNSEvent", database.CollectionTokenApprovals, fftypes.ChangeEventTypeUpdated, approval.Namespace, approval.LocalID, mock.Anything).
 		Return().Once()
 
-	// Initial list is empty
-	fb := database.TokenApprovalQueryFactory.NewFilter(ctx)
-	approvals, _, err := s.GetTokenApprovals(ctx, fb.And())
+	err := s.UpsertTokenApproval(ctx, approval)
 	assert.NoError(t, err)
-	assert.NotNil(t, approvals)
-	assert.Equal(t, 0, len(approvals))
 
-	// Add one approval
-	err = s.UpsertTokenApproval(ctx, approval)
-	assert.NoError(t, err)
 	assert.NotNil(t, approval.Created)
 	approvalJson, _ := json.Marshal(&approval)
 
@@ -85,6 +78,7 @@ func TestApprovalE2EWithDB(t *testing.T) {
 	assert.Equal(t, string(approvalJson), string(approvalReadJson))
 
 	// Query back token approval by query filter
+	fb := database.TokenApprovalQueryFactory.NewFilter(ctx)
 	filter := fb.And(
 		fb.Eq("pool", approval.Pool),
 		fb.Eq("key", approval.Key),
diff --git a/internal/events/websockets/websockets_test.go b/internal/events/websockets/websockets_test.go
index f348e3514..d9901b80b 100644
--- a/internal/events/websockets/websockets_test.go
+++ b/internal/events/websockets/websockets_test.go
@@ -27,6 +27,7 @@ import (
 	"testing"
 
 	"github.com/hyperledger/firefly/internal/coreconfig"
+	"github.com/hyperledger/firefly/internal/coreconfig/wsconfig"
 	"github.com/hyperledger/firefly/mocks/eventsmocks"
 	"github.com/hyperledger/firefly/pkg/config"
 	"github.com/hyperledger/firefly/pkg/events"
@@ -54,13 +55,13 @@ func newTestWebsockets(t *testing.T, cbs *eventsmocks.Callbacks, queryParams ...
 	svr := httptest.NewServer(ws)
 
 	clientPrefix := config.NewPluginConfig("ut.wsclient")
-	wsclient.InitPrefix(clientPrefix)
+	wsconfig.InitPrefix(clientPrefix)
 	qs := ""
 	if len(queryParams) > 0 {
 		qs = fmt.Sprintf("?%s", strings.Join(queryParams, "&"))
 	}
 	clientPrefix.Set(ffresty.HTTPConfigURL, fmt.Sprintf("http://%s%s", svr.Listener.Addr(), qs))
-	wsConfig := wsclient.GenerateConfigFromPrefix(clientPrefix)
+	wsConfig := wsconfig.GenerateConfigFromPrefix(clientPrefix)
 
 	wsc, err := wsclient.New(ctx, wsConfig, nil, nil)
 	assert.NoError(t, err)