user: Refactor user.ID
structure #323
No reviewers
Labels
No labels
P0
P1
P2
P3
good first issue
pool
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-sdk-go#323
Loading…
Reference in a new issue
No description provided.
Delete branch "elebedeva/frostfs-sdk-go:fix/user-id-scripthash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #302, #303
Changed
user.ID.w
field type toutil.Uint160
.util.Uint160
is a byte array of size 20.Signed-off-by: Ekaterina Lebedeva ekaterina.lebedeva@yadro.com
ScriptHash
return no error 761d087b93user.ID
a[20]byte
array873f0896ca
to81c3d4a86f
WIP: user: Refactorto user: Refactoruser.ID
structureuser.ID
structure@ -76,2 +59,2 @@
func (x *ID) ScriptHash() (util.Uint160, error) {
return util.Uint160DecodeBytesBE(x.w[1:21])
func (x *ID) ScriptHash() util.Uint160 {
res, _ := util.Uint160DecodeBytesBE(x.w[:])
Doesn't simple
util.Uint160(x.w)
work?I would argue we can even make
const idSize = util.Uint160Size
andstruct { w util.Uint160 }
It does, thanks! Fixed.
@ -127,3 +112,3 @@
// IsEmpty returns True, if ID is empty value.
func (x ID) IsEmpty() bool {
return bytes.Equal(zeroSlice, x.w)
return bytes.Equal(zeroSlice, x.w[:])
Doesn't
x.w == util.Uint160{}
work?Fixed.
81c3d4a86f
to00cebd297f
New commits pushed, approval review dismissed automatically according to repository settings
New commits pushed, approval review dismissed automatically according to repository settings
@ -84,3 +60,3 @@
// See also Neo3 wallet docs.
func (x ID) WalletBytes() []byte {
return x.w
v := make([]byte, idFullSize)
The comment about
MUST NOT be mutated
can be removed now.@ -91,3 +71,3 @@
// See also DecodeString.
func (x ID) EncodeToString() string {
return base58.Encode(x.w)
return base58.Encode(x.WalletBytes())
EncodeToString()
makes 3 allocations. One of them (insideWalletBytes()
) can be avoided with little cost.One way to achieve this is to move encoding to a function
(ID).encode([]byte)
.Both
WalletBytes()
andEncodeToString()
methods will create new slice andencode
to it.We can do this in another PR, though.