Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 6dc5710

Browse files
authored
Merge pull request #1312 from iotaledger/develop
Merge v0.6.0 to master
2 parents ab10eaf + b9610d7 commit 6dc5710

File tree

187 files changed

+17960
-2072
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+17960
-2072
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# v0.6.0 - 2021-05-19
2+
* Add first iteration of the tokenization framework
3+
* Add aMana refresher
4+
* Add CORS to middleware Dashboard server
5+
* Allow specifying parents count when issuing messages
6+
* Move PoW for Faucet requests to client
7+
* Remove Faucet requests from Node's Dashboard
8+
* Improve cli-wallet
9+
* Improve APIs
10+
* Improve integration tests
11+
* Refactor statement remote logging
12+
* Display full messageID in explorer feed
13+
* Update JS dependencies
14+
* Update documentation
15+
* **Breaking**: bumps network and database versions
16+
117
# v0.5.9 - 2021-05-11
218
* Replace sync beacons with Tangle Time
319
* Fix approval weight manager persistence

client/faucet.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,78 @@
11
package client
22

33
import (
4+
"context"
5+
"crypto"
46
"net/http"
57

8+
"github.com/cockroachdb/errors"
9+
"github.com/iotaledger/hive.go/identity"
10+
"github.com/mr-tron/base58"
11+
12+
"github.com/iotaledger/goshimmer/packages/ledgerstate"
13+
"github.com/iotaledger/goshimmer/packages/mana"
14+
"github.com/iotaledger/goshimmer/packages/pow"
15+
"github.com/iotaledger/goshimmer/plugins/faucet"
616
"github.com/iotaledger/goshimmer/plugins/webapi/jsonmodels"
717
)
818

919
const (
1020
routeFaucet = "faucet"
1121
)
1222

23+
var (
24+
defaultPOWTarget = 25
25+
powWorker = pow.New(crypto.BLAKE2b_512, 1)
26+
)
27+
1328
// SendFaucetRequest requests funds from faucet nodes by sending a faucet request payload message.
14-
func (api *GoShimmerAPI) SendFaucetRequest(base58EncodedAddr string, pledgeIDs ...string) (*jsonmodels.FaucetResponse, error) {
15-
aManaPledgeID, cManaPledgeID := "", ""
29+
func (api *GoShimmerAPI) SendFaucetRequest(base58EncodedAddr string, powTarget int, pledgeIDs ...string) (*jsonmodels.FaucetResponse, error) {
30+
var aManaPledgeID identity.ID
31+
var cManaPledgeID identity.ID
1632
if len(pledgeIDs) > 1 {
17-
aManaPledgeID, cManaPledgeID = pledgeIDs[0], pledgeIDs[1]
33+
aManaPledgeIDFromString, err := mana.IDFromStr(pledgeIDs[0])
34+
if err != nil {
35+
aManaPledgeID = aManaPledgeIDFromString
36+
}
37+
cManaPledgeIDFromString, err := mana.IDFromStr(pledgeIDs[1])
38+
if err != nil {
39+
cManaPledgeID = cManaPledgeIDFromString
40+
}
41+
}
42+
43+
address, err := ledgerstate.AddressFromBase58EncodedString(base58EncodedAddr)
44+
if err != nil {
45+
return nil, errors.Errorf("could not decode address from string: %w", err)
46+
}
47+
48+
nonce, err := computeFaucetPoW(address, aManaPledgeID, cManaPledgeID, powTarget)
49+
if err != nil {
50+
return nil, errors.Errorf("could not compute faucet PoW: %w", err)
1851
}
52+
1953
res := &jsonmodels.FaucetResponse{}
2054
if err := api.do(http.MethodPost, routeFaucet,
21-
&jsonmodels.FaucetRequest{Address: base58EncodedAddr, AccessManaPledgeID: aManaPledgeID, ConsensusManaPledgeID: cManaPledgeID}, res); err != nil {
55+
&jsonmodels.FaucetRequest{
56+
Address: base58EncodedAddr,
57+
AccessManaPledgeID: base58.Encode(aManaPledgeID.Bytes()),
58+
ConsensusManaPledgeID: base58.Encode(cManaPledgeID.Bytes()),
59+
Nonce: nonce,
60+
}, res); err != nil {
2261
return nil, err
2362
}
2463

2564
return res, nil
2665
}
66+
67+
func computeFaucetPoW(address ledgerstate.Address, aManaPledgeID, cManaPledgeID identity.ID, powTarget int) (nonce uint64, err error) {
68+
if powTarget < 0 {
69+
powTarget = defaultPOWTarget
70+
}
71+
72+
faucetRequest := faucet.NewRequest(address, aManaPledgeID, cManaPledgeID, 0)
73+
74+
objectBytes := faucetRequest.Bytes()
75+
powRelevantBytes := objectBytes[:len(objectBytes)-pow.NonceBytes]
76+
77+
return powWorker.Mine(context.Background(), powRelevantBytes, powTarget)
78+
}

client/ledgerstate.go

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package client
2+
3+
import (
4+
"net/http"
5+
"strings"
6+
7+
json_models "github.com/iotaledger/goshimmer/plugins/webapi/jsonmodels"
8+
)
9+
10+
const (
11+
// basic routes
12+
routeGetAddresses = "ledgerstate/addresses/"
13+
routeGetBranches = "ledgerstate/branches/"
14+
routeGetOutputs = "ledgerstate/outputs/"
15+
routeGetTransactions = "ledgerstate/transactions/"
16+
routePostTransactions = "ledgerstate/transactions"
17+
18+
// route path modifiers
19+
pathUnspentOutputs = "/unspentOutputs"
20+
pathChildren = "/children"
21+
pathConflicts = "/conflicts"
22+
pathConsumers = "/consumers"
23+
pathMetadata = "/metadata"
24+
pathInclusionState = "/inclusionState"
25+
pathConsensus = "/consensus"
26+
pathAttachments = "/attachments"
27+
)
28+
29+
// GetAddressOutputs gets the spent and unspent outputs of an address.
30+
func (api *GoShimmerAPI) GetAddressOutputs(base58EncodedAddress string) (*json_models.GetAddressResponse, error) {
31+
res := &json_models.GetAddressResponse{}
32+
if err := api.do(http.MethodGet, func() string {
33+
return strings.Join([]string{routeGetAddresses, base58EncodedAddress}, "")
34+
}(), nil, res); err != nil {
35+
return nil, err
36+
}
37+
return res, nil
38+
}
39+
40+
// GetAddressUnspentOutputs gets the unspent outputs of an address.
41+
func (api *GoShimmerAPI) GetAddressUnspentOutputs(base58EncodedAddress string) (*json_models.GetAddressResponse, error) {
42+
res := &json_models.GetAddressResponse{}
43+
if err := api.do(http.MethodGet, func() string {
44+
return strings.Join([]string{routeGetAddresses, base58EncodedAddress, pathUnspentOutputs}, "")
45+
}(), nil, res); err != nil {
46+
return nil, err
47+
}
48+
return res, nil
49+
}
50+
51+
// PostAddressUnspentOutputs gets the unspent outputs of several addresses.
52+
func (api *GoShimmerAPI) PostAddressUnspentOutputs(base58EncodedAddresses []string) (*json_models.PostAddressesUnspentOutputsResponse, error) {
53+
res := &json_models.PostAddressesUnspentOutputsResponse{}
54+
if err := api.do(http.MethodPost, func() string {
55+
return strings.Join([]string{routeGetAddresses, "unspentOutputs"}, "")
56+
}(), &json_models.PostAddressesUnspentOutputsRequest{Addresses: base58EncodedAddresses}, res); err != nil {
57+
return nil, err
58+
}
59+
return res, nil
60+
}
61+
62+
// GetBranch gets the branch information.
63+
func (api *GoShimmerAPI) GetBranch(base58EncodedBranchID string) (*json_models.Branch, error) {
64+
res := &json_models.Branch{}
65+
if err := api.do(http.MethodGet, func() string {
66+
return strings.Join([]string{routeGetBranches, base58EncodedBranchID}, "")
67+
}(), nil, res); err != nil {
68+
return nil, err
69+
}
70+
return res, nil
71+
}
72+
73+
// GetBranchChildren gets the children of a branch.
74+
func (api *GoShimmerAPI) GetBranchChildren(base58EncodedBranchID string) (*json_models.GetBranchChildrenResponse, error) {
75+
res := &json_models.GetBranchChildrenResponse{}
76+
if err := api.do(http.MethodGet, func() string {
77+
return strings.Join([]string{routeGetBranches, base58EncodedBranchID, pathChildren}, "")
78+
}(), nil, res); err != nil {
79+
return nil, err
80+
}
81+
return res, nil
82+
}
83+
84+
// GetBranchConflicts gets the conflict branches of a branch.
85+
func (api *GoShimmerAPI) GetBranchConflicts(base58EncodedBranchID string) (*json_models.GetBranchConflictsResponse, error) {
86+
res := &json_models.GetBranchConflictsResponse{}
87+
if err := api.do(http.MethodGet, func() string {
88+
return strings.Join([]string{routeGetBranches, base58EncodedBranchID, pathConflicts}, "")
89+
}(), nil, res); err != nil {
90+
return nil, err
91+
}
92+
return res, nil
93+
}
94+
95+
// GetOutput gets the output corresponding to OutputID.
96+
func (api *GoShimmerAPI) GetOutput(base58EncodedOutputID string) (*json_models.Output, error) {
97+
res := &json_models.Output{}
98+
if err := api.do(http.MethodGet, func() string {
99+
return strings.Join([]string{routeGetOutputs, base58EncodedOutputID}, "")
100+
}(), nil, res); err != nil {
101+
return nil, err
102+
}
103+
return res, nil
104+
}
105+
106+
// GetOutputConsumers gets the consumers of the output corresponding to OutputID.
107+
func (api *GoShimmerAPI) GetOutputConsumers(base58EncodedOutputID string) (*json_models.GetOutputConsumersResponse, error) {
108+
res := &json_models.GetOutputConsumersResponse{}
109+
if err := api.do(http.MethodGet, func() string {
110+
return strings.Join([]string{routeGetOutputs, base58EncodedOutputID, pathConsumers}, "")
111+
}(), nil, res); err != nil {
112+
return nil, err
113+
}
114+
return res, nil
115+
}
116+
117+
// GetOutputMetadata gets the metadata of the output corresponding to OutputID.
118+
func (api *GoShimmerAPI) GetOutputMetadata(base58EncodedOutputID string) (*json_models.OutputMetadata, error) {
119+
res := &json_models.OutputMetadata{}
120+
if err := api.do(http.MethodGet, func() string {
121+
return strings.Join([]string{routeGetOutputs, base58EncodedOutputID, pathMetadata}, "")
122+
}(), nil, res); err != nil {
123+
return nil, err
124+
}
125+
return res, nil
126+
}
127+
128+
// GetTransaction gets the transaction of the corresponding to TransactionID.
129+
func (api *GoShimmerAPI) GetTransaction(base58EncodedTransactionID string) (*json_models.Transaction, error) {
130+
res := &json_models.Transaction{}
131+
if err := api.do(http.MethodGet, func() string {
132+
return strings.Join([]string{routeGetTransactions, base58EncodedTransactionID}, "")
133+
}(), nil, res); err != nil {
134+
return nil, err
135+
}
136+
return res, nil
137+
}
138+
139+
// GetTransactionMetadata gets metadata of the transaction corresponding to TransactionID.
140+
func (api *GoShimmerAPI) GetTransactionMetadata(base58EncodedTransactionID string) (*json_models.TransactionMetadata, error) {
141+
res := &json_models.TransactionMetadata{}
142+
if err := api.do(http.MethodGet, func() string {
143+
return strings.Join([]string{routeGetTransactions, base58EncodedTransactionID, pathMetadata}, "")
144+
}(), nil, res); err != nil {
145+
return nil, err
146+
}
147+
return res, nil
148+
}
149+
150+
// GetTransactionInclusionState gets inclusion state of the transaction corresponding to TransactionID.
151+
func (api *GoShimmerAPI) GetTransactionInclusionState(base58EncodedTransactionID string) (*json_models.TransactionInclusionState, error) {
152+
res := &json_models.TransactionInclusionState{}
153+
if err := api.do(http.MethodGet, func() string {
154+
return strings.Join([]string{routeGetTransactions, base58EncodedTransactionID, pathInclusionState}, "")
155+
}(), nil, res); err != nil {
156+
return nil, err
157+
}
158+
return res, nil
159+
}
160+
161+
// GetTransactionConsensusMetadata gets the consensus metadata of the transaction corresponding to TransactionID.
162+
func (api *GoShimmerAPI) GetTransactionConsensusMetadata(base58EncodedTransactionID string) (*json_models.TransactionConsensusMetadata, error) {
163+
res := &json_models.TransactionConsensusMetadata{}
164+
if err := api.do(http.MethodGet, func() string {
165+
return strings.Join([]string{routeGetTransactions, base58EncodedTransactionID, pathConsensus}, "")
166+
}(), nil, res); err != nil {
167+
return nil, err
168+
}
169+
return res, nil
170+
}
171+
172+
// GetTransactionAttachments gets the attachments (messageIDs) of the transaction corresponding to TransactionID.
173+
func (api *GoShimmerAPI) GetTransactionAttachments(base58EncodedTransactionID string) (*json_models.GetTransactionAttachmentsResponse, error) {
174+
res := &json_models.GetTransactionAttachmentsResponse{}
175+
if err := api.do(http.MethodGet, func() string {
176+
return strings.Join([]string{routeGetTransactions, base58EncodedTransactionID, pathAttachments}, "")
177+
}(), nil, res); err != nil {
178+
return nil, err
179+
}
180+
return res, nil
181+
}
182+
183+
// PostTransaction sends the transaction(bytes) to the Tangle and returns its transaction ID.
184+
func (api *GoShimmerAPI) PostTransaction(transactionBytes []byte) (*json_models.PostTransactionResponse, error) {
185+
res := &json_models.PostTransactionResponse{}
186+
if err := api.do(http.MethodPost, routePostTransactions,
187+
&json_models.PostTransactionRequest{TransactionBytes: transactionBytes}, res); err != nil {
188+
return nil, err
189+
}
190+
191+
return res, nil
192+
}

client/mana.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
routePending = "mana/pending"
1919
routePastConsensusVector = "mana/consensus/past"
2020
routePastConsensusEventLogs = "mana/consensus/logs"
21+
routeAllowedPledgeNodeIDs = "mana/allowedManaPledge"
2122
)
2223

2324
// GetOwnMana returns the access and consensus mana of the node this api client is communicating with.
@@ -166,3 +167,13 @@ func (api *GoShimmerAPI) GetConsensusEventLogs(nodeIDs []string) (*jsonmodels.Ge
166167
}
167168
return res, nil
168169
}
170+
171+
// GetAllowedManaPledgeNodeIDs returns the list of allowed mana pledge IDs.
172+
func (api *GoShimmerAPI) GetAllowedManaPledgeNodeIDs() (*jsonmodels.AllowedManaPledgeResponse, error) {
173+
res := &jsonmodels.AllowedManaPledgeResponse{}
174+
if err := api.do(http.MethodGet, routeAllowedPledgeNodeIDs, nil, res); err != nil {
175+
return nil, err
176+
}
177+
178+
return res, nil
179+
}

client/value.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
)
99

1010
const (
11-
routeAttachments = "value/attachments"
12-
routeGetTxnByID = "value/transactionByID"
13-
routeSendTxn = "value/sendTransaction"
14-
routeSendTxnByJSON = "value/sendTransactionByJson"
15-
routeUnspentOutputs = "value/unspentOutputs"
16-
routeAllowedPledgeNodeIDs = "value/allowedManaPledge"
11+
routeAttachments = "value/attachments"
12+
routeGetTxnByID = "value/transactionByID"
13+
routeSendTxn = "value/sendTransaction"
14+
routeSendTxnByJSON = "value/sendTransactionByJson"
15+
routeUnspentOutputs = "value/unspentOutputs"
1716
)
1817

1918
// GetAttachments gets the attachments of a transaction ID
@@ -79,13 +78,3 @@ func (api *GoShimmerAPI) SendTransactionByJSON(txn value.SendTransactionByJSONRe
7978

8079
return res.TransactionID, nil
8180
}
82-
83-
// GetAllowedManaPledgeNodeIDs returns the list of allowed mana pledge IDs.
84-
func (api *GoShimmerAPI) GetAllowedManaPledgeNodeIDs() (*value.AllowedManaPledgeResponse, error) {
85-
res := &value.AllowedManaPledgeResponse{}
86-
if err := api.do(http.MethodGet, routeAllowedPledgeNodeIDs, nil, res); err != nil {
87-
return nil, err
88-
}
89-
90-
return res, nil
91-
}

client/wallet/addressmanager.go renamed to client/wallet/address_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (addressManager *AddressManager) updateFirstUnspentAddressIndex() {
155155
}
156156
}
157157

158-
// updateLastUnspentAddressIndex searches for the first unspent address and updates the lastUnspentAddressIndex.
158+
// updateLastUnspentAddressIndex searches for the last unspent address and updates the lastUnspentAddressIndex.
159159
func (addressManager *AddressManager) updateLastUnspentAddressIndex() {
160160
// search for last unspent address
161161
for i := addressManager.lastUnspentAddressIndex; true; i-- {

client/wallet/balances.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package wallet
2+
3+
import (
4+
"sort"
5+
"time"
6+
7+
"github.com/iotaledger/goshimmer/packages/ledgerstate"
8+
)
9+
10+
// TimedBalance represents a balance that is time dependent.
11+
type TimedBalance struct {
12+
Balance map[ledgerstate.Color]uint64
13+
Time time.Time
14+
}
15+
16+
// TimedBalanceSlice is a slice containing TimedBalances.
17+
type TimedBalanceSlice []*TimedBalance
18+
19+
// Sort sorts the balances based on their Time.
20+
func (t TimedBalanceSlice) Sort() {
21+
sort.Slice(t, func(i, j int) bool {
22+
return t[i].Time.Before(t[j].Time)
23+
})
24+
}

client/wallet/connector.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
// Connector represents an interface that defines how the wallet interacts with the network. A wallet can either be used
1010
// locally on a server or it can connect remotely using the web API.
1111
type Connector interface {
12-
UnspentOutputs(addresses ...address.Address) (unspentOutputs map[address.Address]map[ledgerstate.OutputID]*Output, err error)
12+
UnspentOutputs(addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID, err error)
1313
SendTransaction(transaction *ledgerstate.Transaction) (err error)
14-
RequestFaucetFunds(address address.Address) (err error)
14+
RequestFaucetFunds(address address.Address, powTarget int) (err error)
1515
GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, err error)
16+
GetTransactionInclusionState(txID ledgerstate.TransactionID) (inc ledgerstate.InclusionState, err error)
17+
GetUnspentAliasOutput(address *ledgerstate.AliasAddress) (output *ledgerstate.AliasOutput, err error)
1618
}

0 commit comments

Comments
 (0)