-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Cannot use AccountI inside Protobuf messages #8876
Comments
The way we decided to encode interfaces in Protobuf is using message Profile {
google.Any account = 1 [
(cosmos_proto.accepts_interface) = "AccountI" // At some point we want to make this work, but today it's just informational.
];
string dtag = 2;
// -- snip --
} Then you would do: var myAccount AccountI // Populate it.
// Make sure myAccount is a proto.Message, e.g. a BaseAccount etc.
protoAccount, ok := myAccount.(proto.Message)
myAccountAny := codec.NewAnyWithValue(protoAccount)
myProfile := types.Profile{
Account: myAccountAny,
Dtag: "",
// -- snip --
} Related #8053 (any usage part) |
@AmauryM Thanks for the example. I've thought of this as well, but this makes it extremely difficult to properly implement the |
I believe you can do: func (p Profile) GetPubKey() {
return p.Account.GetCachedValue().(AccountI).GetPubKey()
}
|
Closing this as it is not a bug although maybe the documentation could be clearer. Note also that in order to take the approach @AmauryM described you will need to implement |
|
Summary of Bug
Currently, it is not possible to use the
AccountI
interface inside Protobuf messages. This makes it impossible to implement that interface and create a new custom account type that wraps all already existing account types. It is only possible to extendBaseAccount
,DelayedVestingAccount
and other types individually.Version
v0.42.1
Steps to Reproduce
Currently, inside our application we have the following custom account type:
Objects of such type are then created as follows:
Inside our message handler, we then use the following code to create a new
Profile
instance:The problem with this is that the line
Can throw the following error:
After I saw that error, I tried searching a way to use
types.AccountI
inside the Protobuf message directly. Unfortunately, I found now way of doing this. IMO, I think there should be a way for zone developers to use that interface inside their Protobuf message, otherwise it might become extremely difficult for them to create custom account implementations that should work based on any account type (and not onlyBaseAccount
).For Admin Use
The text was updated successfully, but these errors were encountered: