[#198] object/user: Add ScriptHash method
All checks were successful
Tests and linters / Tests (1.21) (pull_request) Successful in 1m5s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m16s
DCO / DCO (pull_request) Successful in 7m31s
Tests and linters / Lint (pull_request) Successful in 8m29s

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-01-26 14:41:55 +03:00
parent 110b7e4170
commit b0190b809c
2 changed files with 19 additions and 0 deletions

View file

@ -72,6 +72,11 @@ func (x *ID) SetScriptHash(scriptHash util.Uint160) {
copy(x.w[21:], hash.Checksum(x.w[:21])) copy(x.w[21:], hash.Checksum(x.w[:21]))
} }
// ScriptHash calculates and returns script hash of ID.
func (x *ID) ScriptHash() (util.Uint160, error) {
return util.Uint160DecodeBytesBE(x.w[1:21])
}
// WalletBytes returns FrostFS user ID as Neo3 wallet address in a binary format. // WalletBytes returns FrostFS user ID as Neo3 wallet address in a binary format.
// //
// Return value MUST NOT be mutated: to do this, first make a copy. // Return value MUST NOT be mutated: to do this, first make a copy.

View file

@ -8,6 +8,7 @@ import (
. "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" . "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test" usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/util/slice"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -47,6 +48,19 @@ func TestID_SetScriptHash(t *testing.T) {
require.True(t, id2.Equals(id)) require.True(t, id2.Equals(id))
} }
func TestID_ScriptHash(t *testing.T) {
userID := usertest.ID()
scriptHash, err := userID.ScriptHash()
require.NoError(t, err)
ownerAddress := userID.EncodeToString()
decodedScriptHash, err := address.StringToUint160(ownerAddress)
require.NoError(t, err)
require.True(t, scriptHash.Equals(decodedScriptHash))
}
func TestV2_ID(t *testing.T) { func TestV2_ID(t *testing.T) {
id := usertest.ID() id := usertest.ID()
var m refs.OwnerID var m refs.OwnerID