-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
identity deserialization #628
Conversation
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
token/core/common/validator.go
Outdated
@@ -94,7 +93,7 @@ func (v *Validator[P, T, TA, IA]) VerifyTokenRequestFromRaw(getState driver.GetS | |||
return nil, nil, errors.Wrap(err, "failed to marshal signed token request") | |||
} | |||
|
|||
v.Logger.Debugf("cc tx-id [%s][%s]", hash.Hashable(raqRaw).String(), anchor) | |||
v.Logger.Debugf("cc tx-id [%s][%s]", Hashable(raqRaw).String(), anchor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid to call String() in debug logs. It is called lazily
@@ -125,14 +136,15 @@ func (s *TransferService) Transfer(txID string, wallet driver.OwnerWallet, ids [ | |||
} | |||
|
|||
metadata := &driver.TransferMetadata{ | |||
Outputs: outputs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would give more clarity to have a struct:
type OutToken struct {
TokenID
Sender
Output
Metadata
AuditInfo
Receiver
ReceiverAuditInfo
ReceiverIsSender
}
Then the transferMetadata would contain a []OutToken
slice.
This way it's not necessary to read the code to figure out which slice elements are related, and we don't need to check that the lengths are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} | ||
|
||
type TypedVerifierDeserializerMultiplex struct { | ||
deserializers map[string]TypedVerifierDeserializer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use an alias to link this value to the Type
property and even provide constants for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
func (a *AuditDeserializer) DeserializeAuditInfo(bytes []byte) (deserializer.AuditInfo, error) { | ||
si := &ScriptInfo{} | ||
err := json.Unmarshal(bytes, si) | ||
if err == nil && (len(si.Sender) != 0 || len(si.Recipient) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could inverse the condition to reduce nesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} | ||
return nil, errors.Errorf("no recipient defined") | ||
} | ||
return nil, errors.Errorf("ivalid audit info, failed unmarshal [%s]", string(bytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes sense to include also the length of sender/recipient for better debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
return nil, errors.Errorf("failed signer deserialization [%v]", errs) | ||
} | ||
|
||
func (d *multipler) Info(raw []byte, auditInfo []byte) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplication we could have a method:
func deserialize[V](extractor func(driver.Deserializer) (V, err)) {
var errs []error
copyDeserial := d.threadSafeCopyDeserializers()
for _, des := range copyDeserial {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s]", des)
}
v, err := extractor()
if err == nil {
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s] succeeded", des)
}
return v, nil
}
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("trying signer deserialization with [%s] failed [%s]", des, err)
}
errs = append(errs, err)
}
return nil, errors.Errorf("failed signer deserialization [%v]", errs)
}
Then your three methods are almost the same:
func (d *multipler) DeserializeSigner(raw []byte) (driver.Signer, error) {
return deserialize(d.threadSafeCopyDeserializers(), func(des driver.Deserializer) (driver.Signer, error) {return des.DeserializeSigner(raw)})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo comments
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
This PR does the following:
view.Identity
from the smart client in the Token and Driver API. In future PR, the alias will be used everywhere and then the dependency to the smart client removed.Side node: This PR leaves a TODO to be addressed in another PR. The auditor of the zkatdlog driver needs to be updated to better handle the htlc identities and their relative audit information.