Repository: dusk-network/dusk-blockchain (go)

Issue:
Read block reward value from Distribute transaction 
**Describe the bug**
GraphQL should expose block reward value. This issue should describe which note field it is and how to decode it.
 
**Additional context**
[See also](https://github.com/dusk-network/dusk-blockchain/pull/1289#discussion_r805024890)


Pull request:
Decode transparent notes amount
Resolves #1292

Patch:
diff --git a/pkg/core/data/ipc/transactions/note.go b/pkg/core/data/ipc/transactions/note.go
index c2266b2f..abf80ad2 100644
--- a/pkg/core/data/ipc/transactions/note.go
+++ b/pkg/core/data/ipc/transactions/note.go
@@ -10,6 +10,7 @@ import (
 	"bytes"
 
 	"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/encoding"
+	"github.com/sirupsen/logrus"
 )
 
 // Note types.
@@ -97,3 +98,19 @@ func UnmarshalNote(r *bytes.Buffer, f *Note) (err error) {
 
 	return nil
 }
+
+// DecodeTxAmount return the amount of the tx (if transparent).
+func (f *Note) DecodeTxAmount() uint64 {
+	if f.Type != NoteTypeTransparent {
+		logrus.Warn("Note is not transaprent")
+		return 0
+	}
+
+	var txAmount uint64
+	if err := encoding.ReadUint64LE(bytes.NewBuffer(f.EncryptedData), &txAmount); err != nil {
+		logrus.WithError(err).Warn("could not read EncryptedData")
+		return 0
+	}
+
+	return txAmount
+}
diff --git a/pkg/gql/query/blocks.go b/pkg/gql/query/blocks.go
index 2b06aafe..85c3bd96 100644
--- a/pkg/gql/query/blocks.go
+++ b/pkg/gql/query/blocks.go
@@ -7,7 +7,6 @@
 package query
 
 import (
-	"bytes"
 	"encoding/hex"
 	"errors"
 	"time"
@@ -15,9 +14,7 @@ import (
 	"github.com/dusk-network/dusk-blockchain/pkg/core/data/block"
 	core "github.com/dusk-network/dusk-blockchain/pkg/core/data/ipc/transactions"
 	"github.com/dusk-network/dusk-blockchain/pkg/core/database"
-	"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/encoding"
 	"github.com/graphql-go/graphql"
-	"github.com/sirupsen/logrus"
 )
 
 const (
@@ -67,7 +64,7 @@ func newQueryBlock(b *block.Block) queryBlock {
 	qb.Header.Hash = b.Header.Hash
 	qb.Header.StateHash = b.Header.StateHash
 
-	reward := uint32(0)
+	reward := uint64(0)
 	feesPaid := uint64(0)
 
 	for _, tx := range b.Txs {
@@ -75,19 +72,13 @@ func newQueryBlock(b *block.Block) queryBlock {
 
 		if tx.Type() == core.Distribute {
 			distribute, _ := tx.Decode()
-
 			for _, note := range distribute.Notes {
-				var r uint32
-				if err := encoding.ReadUint32LE(bytes.NewBuffer(note.ValueCommitment), &r); err != nil {
-					logrus.WithError(err).Warn("could not read value commitment")
-				}
-
-				reward += r
+				reward += note.DecodeTxAmount()
 			}
 		}
 	}
 
-	qb.Header.Reward = uint64(reward)
+	qb.Header.Reward = reward
 	qb.Header.FeesPaid = feesPaid
 
 	return qb


Test patch:
diff --git a/pkg/p2p/wire/message/transactions_test.go b/pkg/p2p/wire/message/transactions_test.go
index 1653fef0..c9fd32d8 100644
--- a/pkg/p2p/wire/message/transactions_test.go
+++ b/pkg/p2p/wire/message/transactions_test.go
@@ -119,6 +119,8 @@ func TestCoinbaseTransaction(t *testing.T) {
 	assert.Zero(decoded.Fee.GasLimit, "GasLimit should be 0")
 	assert.Zero(decoded.Fee.GasPrice, "GasPrice should be 0")
 	assert.Empty(decoded.Nullifiers, "Nullifiers should not be present")
+	assert.EqualValues(uint64(28113864), decoded.Notes[0].DecodeTxAmount())
+	assert.EqualValues(uint64(253024782), decoded.Notes[1].DecodeTxAmount())
 
 	hash, err := decoded.Hash(txdummy.TxType)
 	if err != nil {