diff --git a/dapps/valuetransfers/packages/tipmanager/tipmanager.go b/dapps/valuetransfers/packages/tipmanager/tipmanager.go index edb1ac8d1edddc0e1df8c6eb3413c19b37414eaf..a989a70484063f06bdc83d59ca4e23dbe6cf3c8d 100644 --- a/dapps/valuetransfers/packages/tipmanager/tipmanager.go +++ b/dapps/valuetransfers/packages/tipmanager/tipmanager.go @@ -77,6 +77,15 @@ func (t *TipManager) Tips() (parent1ObjectID, parent2ObjectID payload.ID) { return } +// AllTips returns all the tips. +func (t *TipManager) AllTips() (tips []payload.ID) { + tips = make([]payload.ID, t.Size()) + for i, tip := range t.tips.Keys() { + tips[i] = tip.(payload.ID) + } + return +} + // Size returns the total liked tips. func (t *TipManager) Size() int { return t.tips.Size() diff --git a/packages/binary/datastructure/random_map.go b/packages/binary/datastructure/random_map.go index 228bc408ab8947480f27e146688a13ebf7f47b4b..08023d2210ece6263dd4be3c9505e1896fd4f74c 100644 --- a/packages/binary/datastructure/random_map.go +++ b/packages/binary/datastructure/random_map.go @@ -135,3 +135,17 @@ func (rmap *RandomMap) RandomEntry() (result interface{}) { return } + +// Keys returns the list of keys stored in the RandomMap. +func (rmap *RandomMap) Keys() (result []interface{}) { + rmap.mutex.RLock() + defer rmap.mutex.RUnlock() + + result = make([]interface{}, rmap.size) + + for i, item := range rmap.keys { + result[i] = item + } + + return +} diff --git a/plugins/webapi/value/plugin.go b/plugins/webapi/value/plugin.go index f9f8a4ca4169943fb4a50ece68ba5738fac0809f..01fd82c7005d387134f480d70769238287d3ebe4 100644 --- a/plugins/webapi/value/plugin.go +++ b/plugins/webapi/value/plugin.go @@ -9,6 +9,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/webapi/value/sendtransaction" "github.com/iotaledger/goshimmer/plugins/webapi/value/sendtransactionbyjson" "github.com/iotaledger/goshimmer/plugins/webapi/value/testsendtxn" + "github.com/iotaledger/goshimmer/plugins/webapi/value/tips" "github.com/iotaledger/goshimmer/plugins/webapi/value/unspentoutputs" "github.com/iotaledger/hive.go/node" ) @@ -37,4 +38,5 @@ func configure(_ *node.Plugin) { webapi.Server().POST("value/sendTransactionByJson", sendtransactionbyjson.Handler) webapi.Server().POST("value/testSendTxn", testsendtxn.Handler) webapi.Server().GET("value/transactionByID", gettransactionbyid.Handler) + webapi.Server().GET("value/tips", tips.Handler) } diff --git a/plugins/webapi/value/tips/handler.go b/plugins/webapi/value/tips/handler.go new file mode 100644 index 0000000000000000000000000000000000000000..3d2b42e132570d26e09648b740a9959e70510cc2 --- /dev/null +++ b/plugins/webapi/value/tips/handler.go @@ -0,0 +1,50 @@ +package tips + +import ( + "net/http" + + "github.com/iotaledger/goshimmer/dapps/valuetransfers" + "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload" + "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/tangle" + "github.com/labstack/echo" +) + +// Handler gets the value object info from the tips. +func Handler(c echo.Context) error { + result := make([]ValueObject, valuetransfers.TipManager().Size()) + for i, valueID := range valuetransfers.TipManager().AllTips() { + var obj ValueObject + valuetransfers.Tangle().PayloadMetadata(valueID).Consume(func(payloadMetadata *tangle.PayloadMetadata) { + obj.ID = payloadMetadata.PayloadID().String() + obj.Solid = payloadMetadata.IsSolid() + obj.Liked = payloadMetadata.Liked() + obj.Confirmed = payloadMetadata.Confirmed() + obj.Rejected = payloadMetadata.Rejected() + obj.BranchID = payloadMetadata.BranchID().String() + }) + + valuetransfers.Tangle().Payload(valueID).Consume(func(p *payload.Payload) { + obj.TransactionID = p.Transaction().ID().String() + }) + + result[i] = obj + } + return c.JSON(http.StatusOK, Response{ValueObjects: result}) +} + +// Response is the HTTP response from retrieving value objects. +type Response struct { + ValueObjects []ValueObject `json:"value_objects,omitempty"` + Error string `json:"error,omitempty"` +} + +// ValueObject holds the info of a ValueObject +type ValueObject struct { + ID string `json:"id"` + Solid bool `json:"solid"` + Liked bool `json:"liked"` + Confirmed bool `json:"confirmed"` + Rejected bool `json:"rejected"` + BranchID string `json:"branch_id"` + TransactionID string `json:"transaction_id"` +} diff --git a/tools/integration-tests/tester/framework/framework.go b/tools/integration-tests/tester/framework/framework.go index 9840c4d76c49788ae9b6f0530d5471a7186a2705..46476e65d2361f9699879765fc30d7b87cf70999 100644 --- a/tools/integration-tests/tester/framework/framework.go +++ b/tools/integration-tests/tester/framework/framework.go @@ -258,7 +258,7 @@ func (f *Framework) CreateDRNGNetwork(name string, members, peers, minimumNeighb } config := GoShimmerConfig{ - DRNGInstance: 1, + DRNGInstance: 111, DRNGThreshold: 3, DRNGDistKey: hex.EncodeToString(drng.distKey), DRNGCommittee: drngCommittee,