[#1618] pkg: Refactor user.ID.ScriptHash()
usage
All checks were successful
DCO action / DCO (pull_request) Successful in 35s
Vulncheck / Vulncheck (pull_request) Successful in 51s
Build / Build Components (pull_request) Successful in 1m21s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m25s
Tests and linters / Run gofumpt (pull_request) Successful in 1m46s
Tests and linters / Staticcheck (pull_request) Successful in 1m59s
Tests and linters / Tests (pull_request) Successful in 2m3s
Tests and linters / Lint (pull_request) Successful in 3m3s
Tests and linters / gopls check (pull_request) Successful in 3m15s
Tests and linters / Tests with -race (pull_request) Successful in 3m54s
All checks were successful
DCO action / DCO (pull_request) Successful in 35s
Vulncheck / Vulncheck (pull_request) Successful in 51s
Build / Build Components (pull_request) Successful in 1m21s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m25s
Tests and linters / Run gofumpt (pull_request) Successful in 1m46s
Tests and linters / Staticcheck (pull_request) Successful in 1m59s
Tests and linters / Tests (pull_request) Successful in 2m3s
Tests and linters / Lint (pull_request) Successful in 3m3s
Tests and linters / gopls check (pull_request) Successful in 3m15s
Tests and linters / Tests with -race (pull_request) Successful in 3m54s
`user.ID.ScriptHash()` does not return an error anymore. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
713f4b144c
commit
ae851b3922
6 changed files with 17 additions and 39 deletions
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
|
||||
git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb5c0d
|
||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20241112082307-f17779933e88
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250109084609-328d214d2d76
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250129133430-d195cb510401
|
||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1
|
||||
git.frostfs.info/TrueCloudLab/multinet v0.0.0-20241015075604-6cb0d80e0972
|
||||
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20240814080254-96225afacb88
|
||||
|
|
4
go.sum
4
go.sum
|
@ -8,8 +8,8 @@ git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb
|
|||
git.frostfs.info/TrueCloudLab/frostfs-locode-db v0.4.1-0.20240710074952-65761deb5c0d/go.mod h1:7ZZq8iguY7qFsXajdHGmZd2AW4QbucyrJwhbsRfOfek=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20241112082307-f17779933e88 h1:9bvBDLApbbO5sXBKdODpE9tzy3HV99nXxkDWNn22rdI=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20241112082307-f17779933e88/go.mod h1:kbwB4v2o6RyOfCo9kEFeUDZIX3LKhmS0yXPrtvzkQ1g=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250109084609-328d214d2d76 h1:wzvSJIiS+p9qKfl3eg1oH6qlrjaEWiqTc/iMDKG3Ml4=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250109084609-328d214d2d76/go.mod h1:aQpPWfG8oyfJ2X+FenPTJpSRWZjwcP5/RAtkW+/VEX8=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250129133430-d195cb510401 h1:5EN6YsbF5u2BffTKo5kVwe+Aqcy6CRTTVKcwZOI+Ym0=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20250129133430-d195cb510401/go.mod h1:aQpPWfG8oyfJ2X+FenPTJpSRWZjwcP5/RAtkW+/VEX8=
|
||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc=
|
||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM=
|
||||
git.frostfs.info/TrueCloudLab/multinet v0.0.0-20241015075604-6cb0d80e0972 h1:/960fWeyn2AFHwQUwDsWB3sbP6lTEnFnMzLMM6tx6N8=
|
||||
|
|
|
@ -11,10 +11,7 @@ import (
|
|||
// BalanceOf receives the amount of funds in the client's account
|
||||
// through the Balance contract call, and returns it.
|
||||
func (c *Client) BalanceOf(id user.ID) (*big.Int, error) {
|
||||
h, err := id.ScriptHash()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h := id.ScriptHash()
|
||||
|
||||
invokePrm := client.TestInvokePrm{}
|
||||
invokePrm.SetMethod(balanceOfMethod)
|
||||
|
|
|
@ -22,22 +22,15 @@ type TransferPrm struct {
|
|||
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
|
||||
// with details p.Details through direct smart contract call.
|
||||
func (c *Client) TransferX(ctx context.Context, p TransferPrm) error {
|
||||
from, err := p.From.ScriptHash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
to, err := p.To.ScriptHash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
from := p.From.ScriptHash()
|
||||
to := p.To.ScriptHash()
|
||||
|
||||
prm := client.InvokePrm{}
|
||||
prm.SetMethod(transferXMethod)
|
||||
prm.SetArgs(from, to, p.Amount, p.Details)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
_, err = c.client.Invoke(ctx, prm)
|
||||
_, err := c.client.Invoke(ctx, prm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invoke method (%s): %w", transferXMethod, err)
|
||||
}
|
||||
|
|
|
@ -649,10 +649,7 @@ func (ac *apeChecker) namespaceByOwner(owner *refs.OwnerID) (string, error) {
|
|||
if err := ownerSDK.ReadFromV2(*owner); err != nil {
|
||||
return "", err
|
||||
}
|
||||
addr, err := ownerSDK.ScriptHash()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
addr := ownerSDK.ScriptHash()
|
||||
|
||||
namespace := ""
|
||||
subject, err := ac.frostFSIDClient.GetSubject(addr)
|
||||
|
@ -674,10 +671,7 @@ func (ac *apeChecker) namespaceByKnownOwner(owner *refs.OwnerID) (string, error)
|
|||
if err := ownerSDK.ReadFromV2(*owner); err != nil {
|
||||
return "", err
|
||||
}
|
||||
addr, err := ownerSDK.ScriptHash()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
addr := ownerSDK.ScriptHash()
|
||||
subject, err := ac.frostFSIDClient.GetSubject(addr)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("get subject error: %w", err)
|
||||
|
|
|
@ -678,8 +678,7 @@ func testDenyPutContainerForOthersSessionToken(t *testing.T) {
|
|||
|
||||
testContainer := containertest.Container()
|
||||
owner := testContainer.Owner()
|
||||
ownerAddr, err := owner.ScriptHash()
|
||||
require.NoError(t, err)
|
||||
ownerAddr := owner.ScriptHash()
|
||||
frostfsIDSubjectReader := &frostfsidStub{
|
||||
subjects: map[util.Uint160]*client.Subject{
|
||||
ownerAddr: {},
|
||||
|
@ -690,7 +689,7 @@ func testDenyPutContainerForOthersSessionToken(t *testing.T) {
|
|||
nm.currentEpoch = 100
|
||||
nm.netmaps = map[uint64]*netmap.NetMap{}
|
||||
|
||||
_, _, err = router.MorphRuleChainStorage().AddMorphRuleChain(chain.Ingress, engine.NamespaceTarget(""), &chain.Chain{
|
||||
_, _, err := router.MorphRuleChainStorage().AddMorphRuleChain(chain.Ingress, engine.NamespaceTarget(""), &chain.Chain{
|
||||
Rules: []chain.Rule{
|
||||
{
|
||||
Status: chain.AccessDenied,
|
||||
|
@ -773,7 +772,7 @@ func testDenyPutContainerReadNamespaceFromFrostfsID(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
req := initPutRequest(t, testContainer)
|
||||
ownerScriptHash := initOwnerIDScriptHash(t, testContainer)
|
||||
ownerScriptHash := initOwnerIDScriptHash(testContainer)
|
||||
|
||||
frostfsIDSubjectReader := &frostfsidStub{
|
||||
subjects: map[util.Uint160]*client.Subject{
|
||||
|
@ -857,7 +856,7 @@ func testDenyPutContainerInvalidNamespace(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
req := initPutRequest(t, testContainer)
|
||||
ownerScriptHash := initOwnerIDScriptHash(t, testContainer)
|
||||
ownerScriptHash := initOwnerIDScriptHash(testContainer)
|
||||
|
||||
frostfsIDSubjectReader := &frostfsidStub{
|
||||
subjects: map[util.Uint160]*client.Subject{
|
||||
|
@ -1532,26 +1531,21 @@ func initPutRequest(t *testing.T, testContainer cnrSDK.Container) *container.Put
|
|||
return req
|
||||
}
|
||||
|
||||
func initOwnerIDScriptHash(t *testing.T, testContainer cnrSDK.Container) util.Uint160 {
|
||||
func initOwnerIDScriptHash(testContainer cnrSDK.Container) util.Uint160 {
|
||||
var ownerSDK *user.ID
|
||||
owner := testContainer.Owner()
|
||||
ownerSDK = &owner
|
||||
sc, err := ownerSDK.ScriptHash()
|
||||
require.NoError(t, err)
|
||||
return sc
|
||||
return ownerSDK.ScriptHash()
|
||||
}
|
||||
|
||||
func initActorOwnerScriptHashes(t *testing.T, actorPK *keys.PrivateKey, ownerPK *keys.PrivateKey) (actorScriptHash util.Uint160, ownerScriptHash util.Uint160) {
|
||||
var actorUserID user.ID
|
||||
user.IDFromKey(&actorUserID, ecdsa.PublicKey(*actorPK.PublicKey()))
|
||||
var err error
|
||||
actorScriptHash, err = actorUserID.ScriptHash()
|
||||
require.NoError(t, err)
|
||||
actorScriptHash = actorUserID.ScriptHash()
|
||||
|
||||
var ownerUserID user.ID
|
||||
user.IDFromKey(&ownerUserID, ecdsa.PublicKey(*ownerPK.PublicKey()))
|
||||
ownerScriptHash, err = ownerUserID.ScriptHash()
|
||||
require.NoError(t, err)
|
||||
ownerScriptHash = ownerUserID.ScriptHash()
|
||||
require.NotEqual(t, ownerScriptHash.String(), actorScriptHash.String())
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue