Skip to content

Commit 26b64e4

Browse files
committed
convert to upgrade
Signed-off-by: Angelo De Caro <[email protected]>
1 parent 1272df6 commit 26b64e4

File tree

17 files changed

+146
-146
lines changed

17 files changed

+146
-146
lines changed

integration/token/fungible/support.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,12 +1254,12 @@ func CheckPrometheusMetrics(ii *integration.Infrastructure, viewName string) {
12541254
}
12551255
}
12561256

1257-
func Conversion(network *integration.Infrastructure, wpm *WalletManagerProvider, user *token3.NodeReference, wallet string, typ token.Type, auditor *token3.NodeReference, issuer *token3.NodeReference, expectedErrorMsgs ...string) string {
1257+
func TokensUpgrade(network *integration.Infrastructure, wpm *WalletManagerProvider, user *token3.NodeReference, wallet string, typ token.Type, auditor *token3.NodeReference, issuer *token3.NodeReference, expectedErrorMsgs ...string) string {
12581258
var recipientData *token2.RecipientData
12591259
if wpm != nil {
12601260
recipientData = wpm.RecipientData(user.Id(), wallet)
12611261
}
1262-
txid, err := network.Client(user.ReplicaName()).CallView("Conversion", common.JSONMarshall(&views.Conversion{
1262+
txid, err := network.Client(user.ReplicaName()).CallView("TokensUpgrade", common.JSONMarshall(&views.TokensUpgrade{
12631263
Wallet: wallet,
12641264
TokenType: typ,
12651265
Issuer: issuer.Id(),
@@ -1269,7 +1269,7 @@ func Conversion(network *integration.Infrastructure, wpm *WalletManagerProvider,
12691269
if len(expectedErrorMsgs) == 0 {
12701270
Expect(err).NotTo(HaveOccurred())
12711271
txID := common.JSONUnmarshalString(txid)
1272-
fmt.Printf("Conversion txID [%s]\n", txID)
1272+
fmt.Printf("TokensUpgrade txID [%s]\n", txID)
12731273
common2.CheckFinality(network, user, txID, nil, false)
12741274
common2.CheckFinality(network, auditor, txID, nil, false)
12751275
common2.CheckFinality(network, issuer, txID, nil, false)

integration/token/fungible/tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ func TestStress(network *integration.Infrastructure, auditorId string, selector
11751175

11761176
}
11771177

1178-
func TestUpdatability(network *integration.Infrastructure, auditorId string, onRestart OnRestartFunc, sel *token3.ReplicaSelector) {
1178+
func TestTokensUpgrade(network *integration.Infrastructure, auditorId string, onRestart OnRestartFunc, sel *token3.ReplicaSelector) {
11791179
// we start with fabtoken 16bits, performs a few operation, and then switch
11801180
auditor := sel.Get(auditorId)
11811181
issuer := sel.Get("issuer")
@@ -1221,7 +1221,7 @@ func TestUpdatability(network *integration.Infrastructure, auditorId string, onR
12211221
CheckBalanceAndHolding(network, alice, "", "EUR", 110, auditor)
12221222

12231223
TransferCash(network, alice, "", "EUR", 110, bob, auditor, "insufficient funds, only [0] tokens of type [EUR] are available, but [110] were requested and no other process has any tokens locked")
1224-
Conversion(network, nil, alice, "", "EUR", auditor, issuer)
1224+
TokensUpgrade(network, nil, alice, "", "EUR", auditor, issuer)
12251225
TransferCash(network, alice, "", "EUR", 110, bob, auditor)
12261226
CopyDBsTo(network, "./testdata", alice)
12271227
CheckOwnerDB(network, nil, issuer, alice, bob, charlie, manager)

integration/token/fungible/topology/topology.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Topology(opts common.Opts) []api.Topology {
6464
)
6565
issuer.AddOptions(opts.ReplicationOpts.For("issuer")...)
6666
issuer.RegisterResponder(&views.WithdrawalResponderView{}, &views.WithdrawalInitiatorView{})
67-
issuer.RegisterResponder(&views.ConversionResponderView{}, &views.ConversionInitiatorView{})
67+
issuer.RegisterResponder(&views.TokensUpgradeResponderView{}, &views.TokensUpgradeInitiatorView{})
6868
issuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{})
6969
issuer.RegisterViewFactory("transfer", &views.TransferViewFactory{})
7070
issuer.RegisterViewFactory("transferWithSelector", &views.TransferWithSelectorViewFactory{})
@@ -210,7 +210,7 @@ func Topology(opts common.Opts) []api.Topology {
210210
alice.RegisterViewFactory("TxFinality", &views2.TxFinalityViewFactory{})
211211
alice.RegisterViewFactory("MaliciousTransfer", &views.MaliciousTransferViewFactory{})
212212
alice.RegisterViewFactory("TxStatus", &views.TxStatusViewFactory{})
213-
alice.RegisterViewFactory("Conversion", &views.ConversionInitiatorViewFactory{})
213+
alice.RegisterViewFactory("TokensUpgrade", &views.TokensUpgradeInitiatorViewFactory{})
214214
alice.RegisterViewFactory("SetSpendableFlag", &views.SetSpendableFlagViewFactory{})
215215

216216
bob := fscTopology.AddNodeByName("bob").AddOptions(
@@ -251,7 +251,7 @@ func Topology(opts common.Opts) []api.Topology {
251251
bob.RegisterViewFactory("RegisterRecipientData", &views.RegisterRecipientDataViewFactory{})
252252
bob.RegisterViewFactory("TxFinality", &views2.TxFinalityViewFactory{})
253253
bob.RegisterViewFactory("TxStatus", &views.TxStatusViewFactory{})
254-
bob.RegisterViewFactory("Conversion", &views.ConversionInitiatorViewFactory{})
254+
bob.RegisterViewFactory("TokensUpgrade", &views.TokensUpgradeInitiatorViewFactory{})
255255

256256
charlie := fscTopology.AddNodeByName("charlie").AddOptions(
257257
fabric.WithOrganization("Org2"),

integration/token/fungible/update/update_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
var _ = Describe("EndToEnd", func() {
2222
for _, t := range integration.AllTestTypes {
23-
Describe("Updatability with Auditor ne Issuer", t.Label, func() {
23+
Describe("Tokens Upgrade with Auditor ne Issuer", t.Label, func() {
2424
ts, selector := newTestSuite(t.CommType, []common.TMSOpts{
2525
{
2626
Alias: "dlog-32bits",
@@ -30,7 +30,7 @@ var _ = Describe("EndToEnd", func() {
3030
}, t.ReplicationFactor, "alice", "bob", "charlie")
3131
BeforeEach(ts.Setup)
3232
AfterEach(ts.TearDown)
33-
It("succeeded", Label("T1"), func() { fungible.TestUpdatability(ts.II, "auditor", nil, selector) })
33+
It("succeeded", Label("T1"), func() { fungible.TestTokensUpgrade(ts.II, "auditor", nil, selector) })
3434
})
3535
}
3636
})

integration/token/fungible/views/conversion.go renamed to integration/token/fungible/views/upgrade.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
2121
)
2222

23-
type Conversion struct {
23+
type TokensUpgrade struct {
2424
// TMSID the token management service identifier
2525
TMSID token.TMSID
2626
// Wallet of the recipient of the cash to be issued
@@ -35,15 +35,15 @@ type Conversion struct {
3535
NotAnonymous bool
3636
}
3737

38-
type ConversionInitiatorView struct {
39-
*Conversion
38+
type TokensUpgradeInitiatorView struct {
39+
*TokensUpgrade
4040
}
4141

42-
func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error) {
43-
span := context.StartSpan("conversion_initiator_view")
42+
func (i *TokensUpgradeInitiatorView) Call(context view.Context) (interface{}, error) {
43+
span := context.StartSpan("upgrade_initiator_view")
4444
defer span.End()
4545

46-
// First, the initiator selects the tokens to convert, namely those that cannot be spent.
46+
// First, the initiator selects the tokens to upgrade, namely those that are unsupported.
4747
tms := token.GetManagementService(context, token.WithTMSID(i.TMSID))
4848
assert.NotNil(tms, "failed getting token management service for [%s]", i.TMSID)
4949
w := tms.WalletManager().OwnerWallet(i.Wallet)
@@ -59,17 +59,17 @@ func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error
5959
unspendableTokens, err := collections.ReadAll(it)
6060
assert.NoError(err, "failed getting tokens")
6161

62-
// Then, the initiator sends a conversion request to the issuer.
62+
// Then, the initiator sends a upgrade request to the issuer.
6363
// If the initiator has already some recipient data, it uses that directly
6464
var id view.Identity
6565
var session view.Session
6666
if i.RecipientData != nil {
6767
// Use the passed RecipientData.
6868
// First register it locally
6969
assert.NoError(w.RegisterRecipient(i.RecipientData), "failed to register remote recipient")
70-
// Then request conversion
71-
span.AddEvent("request_conversion_for_recipient")
72-
id, session, err = ttx.RequestConversionForRecipient(
70+
// Then request upgrade
71+
span.AddEvent("request_upgrade_for_recipient")
72+
id, session, err = ttx.RequestTokensUpgradeForRecipient(
7373
context,
7474
view.Identity(i.Issuer),
7575
i.Wallet,
@@ -79,8 +79,8 @@ func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error
7979
token.WithTMSID(tms.ID()),
8080
)
8181
} else {
82-
span.AddEvent("request_conversion")
83-
id, session, err = ttx.RequestConversion(
82+
span.AddEvent("request_upgrade")
83+
id, session, err = ttx.RequestTokensUpgrade(
8484
context,
8585
view.Identity(i.Issuer),
8686
i.Wallet,
@@ -89,16 +89,16 @@ func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error
8989
token.WithTMSID(tms.ID()),
9090
)
9191
}
92-
assert.NoError(err, "failed to send conversion request")
92+
assert.NoError(err, "failed to send upgrade request")
9393

94-
// Request conversion
94+
// Request upgrade
9595

9696
// At this point we have an inversion of roles.
9797
// The initiator becomes a responder.
9898
// This is a trick to the reuse the same API independently of the role a party plays.
9999
return context.RunView(nil, view.AsResponder(session), view.WithViewCall(
100100
func(context view.Context) (interface{}, error) {
101-
span := context.StartSpan("conversion_respond_view")
101+
span := context.StartSpan("upgrade_respond_view")
102102
defer span.End()
103103
// At some point, the recipient receives the token transaction that in the meantime has been assembled
104104
tx, err := ttx.ReceiveTransaction(context)
@@ -118,7 +118,7 @@ func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error
118118
// If everything is fine, the recipient accepts and sends back her signature.
119119
// Notice that, a signature from the recipient might or might not be required to make the transaction valid.
120120
// This depends on the driver implementation.
121-
span.AddEvent("accept_conversion")
121+
span.AddEvent("accept_upgrade")
122122
_, err = context.RunView(ttx.NewAcceptView(tx))
123123
assert.NoError(err, "failed to accept new tokens")
124124

@@ -132,26 +132,26 @@ func (i *ConversionInitiatorView) Call(context view.Context) (interface{}, error
132132
))
133133
}
134134

135-
type ConversionInitiatorViewFactory struct{}
135+
type TokensUpgradeInitiatorViewFactory struct{}
136136

137-
func (p *ConversionInitiatorViewFactory) NewView(in []byte) (view.View, error) {
138-
f := &ConversionInitiatorView{Conversion: &Conversion{}}
139-
err := json.Unmarshal(in, f.Conversion)
137+
func (p *TokensUpgradeInitiatorViewFactory) NewView(in []byte) (view.View, error) {
138+
f := &TokensUpgradeInitiatorView{TokensUpgrade: &TokensUpgrade{}}
139+
err := json.Unmarshal(in, f.TokensUpgrade)
140140
assert.NoError(err, "failed unmarshalling input")
141141

142142
return f, nil
143143
}
144144

145-
type ConversionResponderView struct {
145+
type TokensUpgradeResponderView struct {
146146
Auditor string
147147
}
148148

149-
func (p *ConversionResponderView) Call(context view.Context) (interface{}, error) {
150-
span := context.StartSpan("conversion_responder_view")
149+
func (p *TokensUpgradeResponderView) Call(context view.Context) (interface{}, error) {
150+
span := context.StartSpan("upgrade_responder_view")
151151
defer span.End()
152-
// First the issuer receives the conversion request
153-
conversionRequest, err := ttx.ReceiveConversionRequest(context)
154-
assert.NoError(err, "failed to receive conversion request")
152+
// First the issuer receives the upgrade request
153+
upgradeRequest, err := ttx.ReceiveTokensUpgradeRequest(context)
154+
assert.NoError(err, "failed to receive upgrade request")
155155

156156
// Now we have an inversion of roles. The issuer becomes an initiator.
157157
// This is a trick to reuse the code used in IssueCashView
@@ -160,7 +160,7 @@ func (p *ConversionResponderView) Call(context view.Context) (interface{}, error
160160
// In this example, if the token type is USD, the issuer checks that no more than 230 units of USD
161161
// have been issued already including the current request.
162162
// No check is performed for other types.
163-
wallet := token.GetManagementService(context, token.WithTMSID(conversionRequest.TMSID)).WalletManager().IssuerWallet("")
163+
wallet := token.GetManagementService(context, token.WithTMSID(upgradeRequest.TMSID)).WalletManager().IssuerWallet("")
164164
assert.NotNil(wallet, "issuer wallet not found")
165165

166166
// At this point, the issuer is ready to prepare the token transaction.
@@ -173,21 +173,21 @@ func (p *ConversionResponderView) Call(context view.Context) (interface{}, error
173173
auditorID = p.Auditor
174174
}
175175
auditor := view2.GetIdentityProvider(context).Identity(auditorID)
176-
if !conversionRequest.NotAnonymous {
176+
if !upgradeRequest.NotAnonymous {
177177
// The issuer creates an anonymous transaction (for Fabric, this means that the resulting transaction will be signed using idemix),
178-
tx, err = ttx.NewAnonymousTransaction(context, ttx.WithAuditor(auditor), ttx.WithTMSID(conversionRequest.TMSID))
178+
tx, err = ttx.NewAnonymousTransaction(context, ttx.WithAuditor(auditor), ttx.WithTMSID(upgradeRequest.TMSID))
179179
} else {
180180
// The issuer creates a nominal transaction using the default identity
181-
tx, err = ttx.NewTransaction(context, nil, ttx.WithAuditor(auditor), ttx.WithTMSID(conversionRequest.TMSID))
181+
tx, err = ttx.NewTransaction(context, nil, ttx.WithAuditor(auditor), ttx.WithTMSID(upgradeRequest.TMSID))
182182
}
183183
assert.NoError(err, "failed creating issue transaction")
184184

185185
// The issuer adds a new issue operation to the transaction following the instruction received
186-
err = tx.Convert(
186+
err = tx.Upgrade(
187187
wallet,
188-
conversionRequest.RecipientData.Identity,
189-
conversionRequest.Tokens,
190-
conversionRequest.Proof,
188+
upgradeRequest.RecipientData.Identity,
189+
upgradeRequest.Tokens,
190+
upgradeRequest.Proof,
191191
)
192192
assert.NoError(err, "failed adding new issued token")
193193

token/core/common/tokens.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func NewTokensService() *TokensService {
1919
return &TokensService{}
2020
}
2121

22-
func (s *TokensService) NewConversionChallenge() (driver.ConversionChallenge, error) {
22+
func (s *TokensService) NewUpgradeChallenge() (driver.TokenUpgradeChallenge, error) {
2323
// generate a 32 bytes secure random slice
2424
key := make([]byte, 32)
2525
_, err := rand.Read(key)
@@ -29,10 +29,10 @@ func (s *TokensService) NewConversionChallenge() (driver.ConversionChallenge, er
2929
return key, nil
3030
}
3131

32-
func (s *TokensService) GenConversionProof(ch driver.ConversionChallenge, tokens []token.LedgerToken) ([]byte, error) {
32+
func (s *TokensService) GenUpgradeProof(ch driver.TokenUpgradeChallenge, tokens []token.LedgerToken) ([]byte, error) {
3333
return nil, nil
3434
}
3535

36-
func (s *TokensService) CheckConversionProof(ch driver.ConversionChallenge, proof driver.ConversionProof, tokens []token.LedgerToken) (bool, error) {
36+
func (s *TokensService) CheckUpgradeProof(ch driver.TokenUpgradeChallenge, proof driver.TokenUpgradeProof, tokens []token.LedgerToken) (bool, error) {
3737
return true, nil
3838
}

token/core/zkatdlog/nogh/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *IssueService) Issue(ctx context.Context, issuerIdentity driver.Identity
8383
}
8484
values = []uint64{totalValue}
8585

86-
s.Logger.Debugf("conversion: extracted token type [%s] and value [%d] from the passed tokens", tokenType, totalValue)
86+
s.Logger.Debugf("upgrade: extracted token type [%s] and value [%d] from the passed tokens", tokenType, totalValue)
8787

8888
// fetch issuer identity
8989
issuerIdentity, err = opts.Wallet.GetIssuerIdentity(tokenType)

token/core/zkatdlog/nogh/tokens.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (s *TokensService) SupportedTokenFormats() []token.Format {
7777

7878
func (s *TokensService) DeserializeToken(outputFormat token.Format, outputRaw []byte, metadataRaw []byte) (*token2.Token, *token2.Metadata, *token2.ConversionWitness, error) {
7979
// Here we have to check if what we get in input is already as expected.
80-
// If not, we need to check if a conversion is possible.
80+
// If not, we need to check if a token upgrade is possible.
8181
// If not, a failure is to be returned
8282
if outputFormat != s.OutputTokenFormat {
8383
return nil, nil, nil, errors.Errorf("invalid token type [%s], expected [%s]", outputFormat, s.OutputTokenFormat)
@@ -99,12 +99,12 @@ func (s *TokensService) DeserializeToken(outputFormat token.Format, outputRaw []
9999
return output, metadata, nil, nil
100100
}
101101

102-
func (s *TokensService) GenConversionProof(ch driver.ConversionChallenge, tokens []token.LedgerToken) ([]byte, error) {
102+
func (s *TokensService) GenUpgradeProof(ch driver.TokenUpgradeChallenge, tokens []token.LedgerToken) ([]byte, error) {
103103
// TODO: implement
104104
return nil, nil
105105
}
106106

107-
func (s *TokensService) CheckConversionProof(ch driver.ConversionChallenge, proof driver.ConversionProof, tokens []token.LedgerToken) (bool, error) {
107+
func (s *TokensService) CheckUpgradeProof(ch driver.TokenUpgradeChallenge, proof driver.TokenUpgradeProof, tokens []token.LedgerToken) (bool, error) {
108108
// TODO: implement
109109
return true, nil
110110
}
@@ -161,15 +161,15 @@ func supportedTokenFormat(pp *crypto.PublicParams) (token.Format, error) {
161161

162162
func (s *TokensService) ProcessTokenConversionRequest(utp *driver.TokenConversionRequest) ([]token.Type, []uint64, error) {
163163
if utp == nil {
164-
return nil, nil, errors.New("nil token conversion request")
164+
return nil, nil, errors.New("nil token upgrade request")
165165
}
166166

167-
ok, err := s.CheckConversionProof(utp.Challenge, utp.Proof, utp.Tokens)
167+
ok, err := s.CheckUpgradeProof(utp.Challenge, utp.Proof, utp.Tokens)
168168
if err != nil {
169-
return nil, nil, errors.Wrap(err, "failed to check conversion proof")
169+
return nil, nil, errors.Wrap(err, "failed to check upgrade proof")
170170
}
171171
if !ok {
172-
return nil, nil, errors.New("invalid conversion proof")
172+
return nil, nil, errors.New("invalid upgrade proof")
173173
}
174174

175175
var tokenTypes []token.Type

token/driver/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
// TokenConversionRequest is a request to convert tokens
1616
type TokenConversionRequest struct {
1717
// Challenge is a challenge to be solved by the prover
18-
Challenge ConversionChallenge
18+
Challenge TokenUpgradeChallenge
1919
// Tokens is a list of tokens to be converted
2020
Tokens []token.LedgerToken
2121
// Proof is a proof that the prover has solved the challenge
22-
Proof ConversionProof
22+
Proof TokenUpgradeProof
2323
}
2424

2525
// IssueOptions models the options that can be passed to the issue command

0 commit comments

Comments
 (0)