Skip to content

Commit 6e01ecb

Browse files
Add contexts
Signed-off-by: Alexandros Filios <alexandros.filios@ibm.com>
1 parent 5aa6226 commit 6e01ecb

File tree

176 files changed

+1657
-1430
lines changed

Some content is hidden

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

176 files changed

+1657
-1430
lines changed

integration/token/dvp/views/balance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ type BalanceView struct {
3333

3434
func (b *BalanceView) Call(context view.Context) (interface{}, error) {
3535
tms := token.GetManagementService(context, token.WithTMSID(b.TMSID))
36-
wallet := tms.WalletManager().OwnerWallet(b.Wallet)
36+
wallet := tms.WalletManager().OwnerWallet(context.Context(), b.Wallet)
3737
if wallet == nil {
3838
return nil, fmt.Errorf("wallet %s not found", b.Wallet)
3939
}
4040

41-
balance, err := wallet.Balance(token.WithType(b.Type))
41+
balance, err := wallet.Balance(context.Context(), token.WithType(b.Type))
4242
if err != nil {
4343
return nil, err
4444
}

integration/token/dvp/views/cash/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p *ListIssuedTokensView) Call(context view.Context) (interface{}, error) {
3434
assert.NotNil(wallet, "wallet [%s] not found", p.Wallet)
3535

3636
// Return the list of issued tokens by type
37-
return wallet.ListIssuedTokens(ttx.WithType(p.TokenType))
37+
return wallet.ListIssuedTokens(context.Context(), ttx.WithType(p.TokenType))
3838
}
3939

4040
type ListIssuedTokensViewFactory struct{}

integration/token/dvp/views/house/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (p *GetHouseView) Call(context view.Context) (interface{}, error) {
2828
assert.NotNil(wallet, "wallet is nil")
2929

3030
house := &House{}
31-
assert.NoError(wallet.QueryByKey(house, "LinearID", p.HouseID), "failed loading house with id %s", p.HouseID)
31+
assert.NoError(wallet.QueryByKey(context.Context(), house, "LinearID", p.HouseID), "failed loading house with id %s", p.HouseID)
3232

3333
return house, nil
3434
}

integration/token/dvp/views/seller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (d *SellHouseView) prepareHouseTransfer(context view.Context, tx *ttx.Trans
8989
assert.NotNil(wallet, "failed getting default wallet")
9090

9191
house := &house.House{}
92-
assert.NoError(wallet.QueryByKey(house, "LinearID", d.HouseID), "failed loading house with id %s", d.HouseID)
92+
assert.NoError(wallet.QueryByKey(context.Context(), house, "LinearID", d.HouseID), "failed loading house with id %s", d.HouseID)
9393

9494
buyer, err := nfttx.RequestRecipientIdentity(context, view.Identity(d.Buyer))
9595
assert.NoError(err, "failed getting buyer identity")

integration/token/fungible/support.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ func RegisterIssuerIdentity(network *integration.Infrastructure, id *token3.Node
11841184
network.Ctx.SetViewClient(walletPath, network.Client(id.ReplicaName()))
11851185
}
11861186

1187-
func RegisterOwnerIdentity(network *integration.Infrastructure, id *token3.NodeReference, identityConfiguration token2.IdentityConfiguration) {
1187+
func RegisterOwnerIdentity(ctx context.Context, network *integration.Infrastructure, id *token3.NodeReference, identityConfiguration token2.IdentityConfiguration) {
11881188
for _, replicaName := range id.AllNames() { // TODO: AF
11891189
_, err := network.Client(replicaName).CallView("RegisterOwnerIdentity", common.JSONMarshall(&views.RegisterOwnerIdentity{
11901190
IdentityConfiguration: identityConfiguration,

integration/token/fungible/tests.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package fungible
88

99
import (
10+
"context"
1011
"crypto/rand"
1112
"fmt"
1213
"math/big"
@@ -908,14 +909,15 @@ func TestPublicParamsUpdate(network *integration.Infrastructure, newAuditorID st
908909

909910
func testTwoGeneratedOwnerWalletsSameNode(network *integration.Infrastructure, auditor *token3.NodeReference, useFabricCA bool, sel *token3.ReplicaSelector, onRestart OnRestartFunc) {
910911

912+
ctx := context.Background()
911913
issuer := sel.Get("issuer")
912914
charlie := sel.Get("charlie")
913915

914916
tokenPlatform := token.GetPlatform(network.Ctx, "token")
915917
idConfig1 := tokenPlatform.GenOwnerCryptoMaterial(tokenPlatform.GetTopology().TMSs[0].BackendTopology.Name(), charlie.Id(), "charlie.ExtraId1", false)
916-
RegisterOwnerIdentity(network, charlie, idConfig1)
918+
RegisterOwnerIdentity(ctx, network, charlie, idConfig1)
917919
idConfig2 := tokenPlatform.GenOwnerCryptoMaterial(tokenPlatform.GetTopology().TMSs[0].BackendTopology.Name(), charlie.Id(), "charlie.ExtraId2", useFabricCA)
918-
RegisterOwnerIdentity(network, charlie, idConfig2)
920+
RegisterOwnerIdentity(ctx, network, charlie, idConfig2)
919921

920922
IssueCash(network, "", "SPE", 100, charlie, auditor, true, issuer)
921923
TransferCash(network, charlie, "", "SPE", 25, sel.Get("charlie.ExtraId1"), auditor)

integration/token/fungible/views/accept.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (a *AcceptCashView) Call(context view.Context) (interface{}, error) {
4242
if output.Type == "MAX" {
4343
continue
4444
}
45-
balance, err := ttx.MyWallet(context, token.WithTMSID(tx.TMSID())).Balance(ttx.WithType(output.Type))
45+
balance, err := ttx.MyWallet(context, token.WithTMSID(tx.TMSID())).Balance(context.Context(), ttx.WithType(output.Type))
4646
assert.NoError(err, "failed retrieving balance for type [%s]", output.Type)
4747
assert.True(balance <= 3000, "cannot have more than 3000 unspent quantity for type [%s]", output.Type)
4848
}
@@ -56,7 +56,7 @@ func (a *AcceptCashView) Call(context view.Context) (interface{}, error) {
5656
// Sanity checks:
5757
// - the transaction is in pending state
5858
owner := ttx.NewOwner(context, tx.TokenService())
59-
vc, _, err := owner.GetStatus(tx.ID())
59+
vc, _, err := owner.GetStatus(context.Context(), tx.ID())
6060
assert.NoError(err, "failed to retrieve status for transaction [%s]", tx.ID())
6161
assert.Equal(ttx.Pending, vc, "transaction [%s] should be in busy state", tx.ID())
6262

@@ -66,7 +66,7 @@ func (a *AcceptCashView) Call(context view.Context) (interface{}, error) {
6666

6767
// Sanity checks:
6868
// - the transaction is in confirmed state
69-
vc, _, err = owner.GetStatus(tx.ID())
69+
vc, _, err = owner.GetStatus(context.Context(), tx.ID())
7070
assert.NoError(err, "failed to retrieve status for transaction [%s]", tx.ID())
7171
assert.Equal(ttx.Confirmed, vc, "transaction [%s] should be in valid state", tx.ID())
7272

integration/token/fungible/views/auditor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (a *AuditView) Call(context view.Context) (interface{}, error) {
5656

5757
// extract inputs and outputs
5858
logger.Debugf("AuditView: audit [%s]", tx.ID())
59-
inputs, outputs, err := auditor.Audit(tx)
59+
inputs, outputs, err := auditor.Audit(context.Context(), tx)
6060
assert.NoError(err, "failed retrieving inputs and outputs")
6161
logger.Debugf("AuditView: audit done [%s]", tx.ID())
6262
defer auditor.Release(tx)
@@ -108,7 +108,7 @@ func (a *AuditView) Call(context view.Context) (interface{}, error) {
108108
fmt.Printf("Cumulative Limit: [%s] Diff [%d], type [%s]\n", eID, diff.Int64(), tokenType)
109109

110110
// load last 10 payments, add diff, and check that it is below the threshold
111-
filter, err := auditor.NewPaymentsFilter().ByEnrollmentId(eID).ByType(tokenType).Last(10).Execute()
111+
filter, err := auditor.NewPaymentsFilter().ByEnrollmentId(eID).ByType(tokenType).Last(10).Execute(context.Context())
112112
assert.NoError(err, "failed retrieving last 10 payments")
113113
sumLastPayments := filter.Sum()
114114
fmt.Printf("Cumulative Limit: [%s] Last NewPaymentsFilter [%s], type [%s]\n", eID, sumLastPayments.Text(10), tokenType)
@@ -141,7 +141,7 @@ func (a *AuditView) Call(context view.Context) (interface{}, error) {
141141
fmt.Printf("Holding Limit: [%s] Diff [%d], type [%s]\n", eID, diff.Int64(), tokenType)
142142

143143
// load current holding, add diff, and check that it is below the threshold
144-
filter, err := auditor.NewHoldingsFilter().ByEnrollmentId(eID).ByType(tokenType).Execute()
144+
filter, err := auditor.NewHoldingsFilter().ByEnrollmentId(eID).ByType(tokenType).Execute(context.Context())
145145
assert.NoError(err, "failed retrieving holding for [%s][%s]", eIDs, tokenTypes)
146146
currentHolding := filter.Sum()
147147

@@ -221,13 +221,13 @@ func (r *CurrentHoldingView) Call(context view.Context) (interface{}, error) {
221221
tms := token.GetManagementService(context, token.WithTMSID(r.TMSID))
222222
assert.NotNil(tms, "tms not found [%s]", r.TMSID)
223223

224-
w := tms.WalletManager().AuditorWallet("")
224+
w := tms.WalletManager().AuditorWallet(context.Context(), "")
225225
assert.NotNil(w, "failed getting default auditor wallet")
226226

227227
auditor, err := ttx.NewAuditor(context, w)
228228
assert.NoError(err, "failed to get auditor instance")
229229

230-
filter, err := auditor.NewHoldingsFilter().ByEnrollmentId(r.EnrollmentID).ByType(r.TokenType).Execute()
230+
filter, err := auditor.NewHoldingsFilter().ByEnrollmentId(r.EnrollmentID).ByType(r.TokenType).Execute(context.Context())
231231
assert.NoError(err, "failed retrieving holding for [%s][%s]", r.EnrollmentID, r.TokenType)
232232
currentHolding := filter.Sum()
233233
decimal := currentHolding.Text(10)
@@ -264,7 +264,7 @@ func (r *CurrentSpendingView) Call(context view.Context) (interface{}, error) {
264264
auditor, err := ttx.NewAuditor(context, w)
265265
assert.NoError(err, "failed to get auditor instance")
266266

267-
filter, err := auditor.NewPaymentsFilter().ByEnrollmentId(r.EnrollmentID).ByType(r.TokenType).Execute()
267+
filter, err := auditor.NewPaymentsFilter().ByEnrollmentId(r.EnrollmentID).ByType(r.TokenType).Execute(context.Context())
268268
assert.NoError(err, "failed retrieving spending for [%s][%s]", r.EnrollmentID, r.TokenType)
269269
currentSpending := filter.Sum()
270270
decimal := currentSpending.Text(10)

integration/token/fungible/views/balance.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (b *BalanceView) Call(context view.Context) (interface{}, error) {
4242
defer span.AddEvent("end_balance_view")
4343
span.AddEvent("start_balance_view")
4444
tms := token.GetManagementService(context, ServiceOpts(b.TMSID)...)
45-
wallet := tms.WalletManager().OwnerWallet(b.Wallet)
45+
wallet := tms.WalletManager().OwnerWallet(context.Context(), b.Wallet)
4646
if wallet == nil {
4747
return nil, fmt.Errorf("wallet %s not found", b.Wallet)
4848
}
@@ -61,14 +61,14 @@ func (b *BalanceView) Call(context view.Context) (interface{}, error) {
6161

6262
// co-owned
6363
multisigWallet := multisig.Wallet(context, wallet)
64-
coOwnedTokens, err := multisigWallet.ListTokensIterator(token.WithType(b.Type))
64+
coOwnedTokens, err := multisigWallet.ListTokensIterator(context.Context(), token.WithType(b.Type))
6565
assert.NoError(err, "failed to get co-owned tokens")
6666
coOwned, err := iterators.Reduce(coOwnedTokens, token2.ToQuantitySum(precision))
6767
assert.NoError(err, "failed to compute the sum of the co-owned tokens")
6868

6969
if !b.SkipCheck {
7070
span.AddEvent("start_sum_calculation")
71-
balance, err := wallet.Balance(token.WithType(b.Type))
71+
balance, err := wallet.Balance(context.Context(), token.WithType(b.Type))
7272
if err != nil {
7373
return nil, err
7474
}
@@ -107,15 +107,15 @@ type CoOwnedBalanceView struct {
107107

108108
func (b *CoOwnedBalanceView) Call(context view.Context) (interface{}, error) {
109109
tms := token.GetManagementService(context, ServiceOpts(b.TMSID)...)
110-
wallet := tms.WalletManager().OwnerWallet(b.Wallet)
110+
wallet := tms.WalletManager().OwnerWallet(context.Context(), b.Wallet)
111111
if wallet == nil {
112112
return nil, fmt.Errorf("wallet %s not found", b.Wallet)
113113
}
114114

115115
// co-owned
116116
precision := tms.PublicParametersManager().PublicParameters().Precision()
117117
multisigWallet := multisig.Wallet(context, wallet)
118-
coOwnedTokens, err := multisigWallet.ListTokensIterator(token.WithType(b.Type))
118+
coOwnedTokens, err := multisigWallet.ListTokensIterator(context.Context(), token.WithType(b.Type))
119119
assert.NoError(err, "failed to get co-owned tokens")
120120
coOwned, err := iterators.Reduce(coOwnedTokens, token2.ToQuantitySum(precision))
121121
assert.NoError(err, "failed to compute the sum of the co-owned tokens")

integration/token/fungible/views/checks.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package views
88

99
import (
10+
"context"
1011
"encoding/json"
1112

1213
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
@@ -22,8 +23,8 @@ import (
2223
)
2324

2425
type TokenTransactionDB interface {
25-
GetTokenRequest(txID string) ([]byte, error)
26-
Transactions(params driver.QueryTransactionsParams, pagination driver2.Pagination) (*driver2.PageIterator[*driver.TransactionRecord], error)
26+
GetTokenRequest(ctx context.Context, txID string) ([]byte, error)
27+
Transactions(ctx context.Context, params driver.QueryTransactionsParams, pagination driver2.Pagination) (*driver2.PageIterator[*driver.TransactionRecord], error)
2728
}
2829

2930
type CheckTTXDB struct {
@@ -52,7 +53,7 @@ func (m *CheckTTXDBView) Call(context view.Context) (interface{}, error) {
5253
tms := token.GetManagementService(context, token.WithTMSID(m.TMSID))
5354
assert.NotNil(tms, "failed to get default tms")
5455
if m.Auditor {
55-
auditorWallet := tms.WalletManager().AuditorWallet(m.AuditorWalletID)
56+
auditorWallet := tms.WalletManager().AuditorWallet(context.Context(), m.AuditorWalletID)
5657
assert.NotNil(auditorWallet, "cannot find auditor wallet [%s]", m.AuditorWalletID)
5758
db, err := ttx.NewAuditor(context, auditorWallet)
5859
assert.NoError(err, "failed to get auditor instance")
@@ -110,7 +111,7 @@ type ListVaultUnspentTokensView struct {
110111
func (l *ListVaultUnspentTokensView) Call(context view.Context) (interface{}, error) {
111112
net := token.GetManagementService(context, token.WithTMSID(l.TMSID))
112113
assert.NotNil(net, "cannot find tms [%s]", l.TMSID)
113-
return net.Vault().NewQueryEngine().ListUnspentTokens()
114+
return net.Vault().NewQueryEngine().ListUnspentTokens(context.Context())
114115
}
115116

116117
type ListVaultUnspentTokensViewFactory struct{}
@@ -138,7 +139,7 @@ func (c *CheckIfExistsInVaultView) Call(context view.Context) (interface{}, erro
138139
qe := tms.Vault().NewQueryEngine()
139140
var IDs []*token2.ID
140141
count := 0
141-
assert.NoError(qe.GetTokenOutputs(c.IDs, func(id *token2.ID, tokenRaw []byte) error {
142+
assert.NoError(qe.GetTokenOutputs(context.Context(), c.IDs, func(id *token2.ID, tokenRaw []byte) error {
142143
if len(tokenRaw) == 0 {
143144
return errors.Errorf("token id [%s] is nil", id)
144145
}

0 commit comments

Comments
 (0)