fix: update account table interface to use address, chain and network

This commit is contained in:
Prad Nukala
2024-09-27 21:15:20 -04:00
parent d06dfb5a93
commit 06daff4b33
4 changed files with 100 additions and 84 deletions
+27 -13
View File
@@ -144,9 +144,9 @@ type AccountTable interface {
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*Account, error)
HasByAccount(ctx context.Context, account string) (found bool, err error)
// GetByAccount returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetByAccount(ctx context.Context, account string) (*Account, error)
HasByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (found bool, err error)
// GetByAddressChainNetwork returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (*Account, error)
List(ctx context.Context, prefixKey AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error)
ListRange(ctx context.Context, from, to AccountIndexKey, opts ...ormlist.Option) (AccountIterator, error)
DeleteBy(ctx context.Context, prefixKey AccountIndexKey) error
@@ -187,16 +187,26 @@ func (this AccountIdIndexKey) WithId(id uint64) AccountIdIndexKey {
return this
}
type AccountAccountIndexKey struct {
type AccountAddressChainNetworkIndexKey struct {
vs []interface{}
}
func (x AccountAccountIndexKey) id() uint32 { return 1 }
func (x AccountAccountIndexKey) values() []interface{} { return x.vs }
func (x AccountAccountIndexKey) accountIndexKey() {}
func (x AccountAddressChainNetworkIndexKey) id() uint32 { return 1 }
func (x AccountAddressChainNetworkIndexKey) values() []interface{} { return x.vs }
func (x AccountAddressChainNetworkIndexKey) accountIndexKey() {}
func (this AccountAccountIndexKey) WithAccount(account string) AccountAccountIndexKey {
this.vs = []interface{}{account}
func (this AccountAddressChainNetworkIndexKey) WithAddress(address string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address}
return this
}
func (this AccountAddressChainNetworkIndexKey) WithAddressChain(address string, chain string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address, chain}
return this
}
func (this AccountAddressChainNetworkIndexKey) WithAddressChainNetwork(address string, chain string, network string) AccountAddressChainNetworkIndexKey {
this.vs = []interface{}{address, chain, network}
return this
}
@@ -236,16 +246,20 @@ func (this accountTable) Get(ctx context.Context, id uint64) (*Account, error) {
return &account, nil
}
func (this accountTable) HasByAccount(ctx context.Context, account string) (found bool, err error) {
func (this accountTable) HasByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (found bool, err error) {
return this.table.GetIndexByID(1).(ormtable.UniqueIndex).Has(ctx,
account,
address,
chain,
network,
)
}
func (this accountTable) GetByAccount(ctx context.Context, account string) (*Account, error) {
func (this accountTable) GetByAddressChainNetwork(ctx context.Context, address string, chain string, network string) (*Account, error) {
var account Account
found, err := this.table.GetIndexByID(1).(ormtable.UniqueIndex).Get(ctx, &account,
account,
address,
chain,
network,
)
if err != nil {
return nil, err
+42 -41
View File
@@ -484,7 +484,7 @@ func (x *fastReflection_Balance) ProtoMethods() *protoiface.Methods {
var (
md_Account protoreflect.MessageDescriptor
fd_Account_id protoreflect.FieldDescriptor
fd_Account_account protoreflect.FieldDescriptor
fd_Account_address protoreflect.FieldDescriptor
fd_Account_chain protoreflect.FieldDescriptor
fd_Account_network protoreflect.FieldDescriptor
)
@@ -493,7 +493,7 @@ func init() {
file_oracle_v1_state_proto_init()
md_Account = File_oracle_v1_state_proto.Messages().ByName("Account")
fd_Account_id = md_Account.Fields().ByName("id")
fd_Account_account = md_Account.Fields().ByName("account")
fd_Account_address = md_Account.Fields().ByName("address")
fd_Account_chain = md_Account.Fields().ByName("chain")
fd_Account_network = md_Account.Fields().ByName("network")
}
@@ -569,9 +569,9 @@ func (x *fastReflection_Account) Range(f func(protoreflect.FieldDescriptor, prot
return
}
}
if x.Account != "" {
value := protoreflect.ValueOfString(x.Account)
if !f(fd_Account_account, value) {
if x.Address != "" {
value := protoreflect.ValueOfString(x.Address)
if !f(fd_Account_address, value) {
return
}
}
@@ -604,8 +604,8 @@ func (x *fastReflection_Account) Has(fd protoreflect.FieldDescriptor) bool {
switch fd.FullName() {
case "oracle.v1.Account.id":
return x.Id != uint64(0)
case "oracle.v1.Account.account":
return x.Account != ""
case "oracle.v1.Account.address":
return x.Address != ""
case "oracle.v1.Account.chain":
return x.Chain != ""
case "oracle.v1.Account.network":
@@ -628,8 +628,8 @@ func (x *fastReflection_Account) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "oracle.v1.Account.id":
x.Id = uint64(0)
case "oracle.v1.Account.account":
x.Account = ""
case "oracle.v1.Account.address":
x.Address = ""
case "oracle.v1.Account.chain":
x.Chain = ""
case "oracle.v1.Account.network":
@@ -653,8 +653,8 @@ func (x *fastReflection_Account) Get(descriptor protoreflect.FieldDescriptor) pr
case "oracle.v1.Account.id":
value := x.Id
return protoreflect.ValueOfUint64(value)
case "oracle.v1.Account.account":
value := x.Account
case "oracle.v1.Account.address":
value := x.Address
return protoreflect.ValueOfString(value)
case "oracle.v1.Account.chain":
value := x.Chain
@@ -684,8 +684,8 @@ func (x *fastReflection_Account) Set(fd protoreflect.FieldDescriptor, value prot
switch fd.FullName() {
case "oracle.v1.Account.id":
x.Id = value.Uint()
case "oracle.v1.Account.account":
x.Account = value.Interface().(string)
case "oracle.v1.Account.address":
x.Address = value.Interface().(string)
case "oracle.v1.Account.chain":
x.Chain = value.Interface().(string)
case "oracle.v1.Account.network":
@@ -712,8 +712,8 @@ func (x *fastReflection_Account) Mutable(fd protoreflect.FieldDescriptor) protor
switch fd.FullName() {
case "oracle.v1.Account.id":
panic(fmt.Errorf("field id of message oracle.v1.Account is not mutable"))
case "oracle.v1.Account.account":
panic(fmt.Errorf("field account of message oracle.v1.Account is not mutable"))
case "oracle.v1.Account.address":
panic(fmt.Errorf("field address of message oracle.v1.Account is not mutable"))
case "oracle.v1.Account.chain":
panic(fmt.Errorf("field chain of message oracle.v1.Account is not mutable"))
case "oracle.v1.Account.network":
@@ -733,7 +733,7 @@ func (x *fastReflection_Account) NewField(fd protoreflect.FieldDescriptor) proto
switch fd.FullName() {
case "oracle.v1.Account.id":
return protoreflect.ValueOfUint64(uint64(0))
case "oracle.v1.Account.account":
case "oracle.v1.Account.address":
return protoreflect.ValueOfString("")
case "oracle.v1.Account.chain":
return protoreflect.ValueOfString("")
@@ -811,7 +811,7 @@ func (x *fastReflection_Account) ProtoMethods() *protoiface.Methods {
if x.Id != 0 {
n += 1 + runtime.Sov(uint64(x.Id))
}
l = len(x.Account)
l = len(x.Address)
if l > 0 {
n += 1 + l + runtime.Sov(uint64(l))
}
@@ -866,10 +866,10 @@ func (x *fastReflection_Account) ProtoMethods() *protoiface.Methods {
i--
dAtA[i] = 0x1a
}
if len(x.Account) > 0 {
i -= len(x.Account)
copy(dAtA[i:], x.Account)
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Account)))
if len(x.Address) > 0 {
i -= len(x.Address)
copy(dAtA[i:], x.Address)
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Address)))
i--
dAtA[i] = 0x12
}
@@ -948,7 +948,7 @@ func (x *fastReflection_Account) ProtoMethods() *protoiface.Methods {
}
case 2:
if wireType != 2 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Account", wireType)
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Address", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
@@ -976,7 +976,7 @@ func (x *fastReflection_Account) ProtoMethods() *protoiface.Methods {
if postIndex > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
x.Account = string(dAtA[iNdEx:postIndex])
x.Address = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
@@ -1139,7 +1139,7 @@ type Account struct {
unknownFields protoimpl.UnknownFields
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
Chain string `protobuf:"bytes,3,opt,name=chain,proto3" json:"chain,omitempty"`
Network string `protobuf:"bytes,4,opt,name=network,proto3" json:"network,omitempty"`
}
@@ -1171,9 +1171,9 @@ func (x *Account) GetId() uint64 {
return 0
}
func (x *Account) GetAccount() string {
func (x *Account) GetAddress() string {
if x != nil {
return x.Account
return x.Address
}
return ""
}
@@ -1204,25 +1204,26 @@ var file_oracle_v1_state_proto_rawDesc = []byte{
0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04,
0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x1f, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x19,
0x0a, 0x09, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x0a, 0x0a, 0x06, 0x61,
0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x10, 0x01, 0x18, 0x01, 0x22, 0x82, 0x01, 0x0a, 0x07, 0x41, 0x63,
0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x10, 0x01, 0x18, 0x01, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x41, 0x63,
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12,
0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12,
0x14, 0x0a, 0x05, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x63, 0x68, 0x61, 0x69, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x3a,
0x1d, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x17, 0x0a, 0x04, 0x0a, 0x02, 0x69, 0x64, 0x12, 0x0d, 0x0a,
0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x10, 0x01, 0x18, 0x01, 0x18, 0x02, 0x42, 0x8f,
0x01, 0x0a, 0x0d, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x2e, 0x76, 0x31,
0x42, 0x0a, 0x53, 0x74, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6e, 0x73, 0x6f, 0x6e,
0x72, 0x2f, 0x73, 0x6f, 0x6e, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x72, 0x61, 0x63, 0x6c,
0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03,
0x4f, 0x58, 0x58, 0xaa, 0x02, 0x09, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca,
0x02, 0x09, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x15, 0x4f, 0x72,
0x61, 0x63, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64,
0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x2b, 0xf2, 0x9e, 0xd3, 0x8e, 0x03, 0x25, 0x0a, 0x04, 0x0a, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a,
0x15, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2c, 0x6e,
0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x10, 0x01, 0x18, 0x01, 0x18, 0x02, 0x42, 0x8f, 0x01, 0x0a,
0x0d, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0a,
0x53, 0x74, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x6e, 0x73, 0x6f, 0x6e, 0x72, 0x2f,
0x73, 0x6f, 0x6e, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x2f,
0x76, 0x31, 0x3b, 0x6f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x58,
0x58, 0xaa, 0x02, 0x09, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x09,
0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x15, 0x4f, 0x72, 0x61, 0x63,
0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0xea, 0x02, 0x0a, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (