forked from TrueCloudLab/frostfs-node
[#2091] morph/client: Simplify code
1. Replace `mn` function with a `sigCount`. 2. Use `notary.FakeMultisigAccount` for account creation. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
cfefebd5b3
commit
b93be8869b
1 changed files with 14 additions and 27 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
||||||
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
@ -426,8 +425,7 @@ func (c *Client) notaryInvoke(committee, invokedByAlpha bool, contract util.Uint
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, n := mn(alphabetList, committee)
|
u8n := uint8(len(alphabetList))
|
||||||
u8n := uint8(n)
|
|
||||||
|
|
||||||
if !invokedByAlpha {
|
if !invokedByAlpha {
|
||||||
u8n++
|
u8n++
|
||||||
|
@ -541,7 +539,7 @@ func (c *Client) notaryCosigners(invokedByAlpha bool, ir []*keys.PublicKey, comm
|
||||||
})
|
})
|
||||||
|
|
||||||
// then we have inner ring multiaddress signature
|
// then we have inner ring multiaddress signature
|
||||||
m, _ := mn(ir, committee)
|
m := sigCount(ir, committee)
|
||||||
|
|
||||||
multisigScript, err := sc.CreateMultiSigRedeemScript(m, ir)
|
multisigScript, err := sc.CreateMultiSigRedeemScript(m, ir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -675,10 +673,10 @@ func (c *Client) notaryWitnesses(invokedByAlpha bool, multiaddr *wallet.Account,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) notaryMultisigAccount(ir []*keys.PublicKey, committee, invokedByAlpha bool) (*wallet.Account, error) {
|
func (c *Client) notaryMultisigAccount(ir []*keys.PublicKey, committee, invokedByAlpha bool) (*wallet.Account, error) {
|
||||||
m, _ := mn(ir, committee)
|
m := sigCount(ir, committee)
|
||||||
|
|
||||||
var multisigAccount *wallet.Account
|
var multisigAccount *wallet.Account
|
||||||
|
var err error
|
||||||
if invokedByAlpha {
|
if invokedByAlpha {
|
||||||
multisigAccount = wallet.NewAccountFromPrivateKey(c.acc.PrivateKey())
|
multisigAccount = wallet.NewAccountFromPrivateKey(c.acc.PrivateKey())
|
||||||
err := multisigAccount.ConvertMultisig(m, ir)
|
err := multisigAccount.ConvertMultisig(m, ir)
|
||||||
|
@ -687,19 +685,13 @@ func (c *Client) notaryMultisigAccount(ir []*keys.PublicKey, committee, invokedB
|
||||||
return nil, wrapNeoFSError(fmt.Errorf("can't convert account to inner ring multisig wallet: %w", err))
|
return nil, wrapNeoFSError(fmt.Errorf("can't convert account to inner ring multisig wallet: %w", err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
script, err := smartcontract.CreateMultiSigRedeemScript(m, ir)
|
|
||||||
if err != nil {
|
|
||||||
// wrap error as NeoFS-specific since the call is not related to any client
|
|
||||||
return nil, wrapNeoFSError(fmt.Errorf("can't make inner ring multisig wallet: %w", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// alphabet multisig redeem script is
|
// alphabet multisig redeem script is
|
||||||
// used as verification script for
|
// used as verification script for
|
||||||
// inner ring multiaddress witness
|
// inner ring multiaddress witness
|
||||||
multisigAccount = &wallet.Account{
|
multisigAccount, err = notary.FakeMultisigAccount(m, ir)
|
||||||
Contract: &wallet.Contract{
|
if err != nil {
|
||||||
Script: script,
|
// wrap error as NeoFS-specific since the call is not related to any client
|
||||||
},
|
return nil, wrapNeoFSError(fmt.Errorf("can't make inner ring multisig wallet: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,19 +743,14 @@ func invocationParams(args ...interface{}) ([]sc.Parameter, error) {
|
||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// mn returns M and N multi signature numbers. For NeoFS N is a length of
|
// sigCount returns the number of required signature.
|
||||||
// inner ring list, and M is a 2/3+1 of it (like in dBFT). If committee is
|
// For NeoFS Alphabet M is a 2/3+1 of it (like in dBFT).
|
||||||
// true, returns M as N/2+1.
|
// If committee is true, returns M as N/2+1.
|
||||||
func mn(ir []*keys.PublicKey, committee bool) (m int, n int) {
|
func sigCount(ir []*keys.PublicKey, committee bool) int {
|
||||||
n = len(ir)
|
|
||||||
|
|
||||||
if committee {
|
if committee {
|
||||||
m = n/2 + 1
|
return sc.GetMajorityHonestNodeCount(len(ir))
|
||||||
} else {
|
|
||||||
m = n*2/3 + 1
|
|
||||||
}
|
}
|
||||||
|
return sc.GetDefaultHonestNodeCount(len(ir))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithTxValidTime returns a notary support option for client
|
// WithTxValidTime returns a notary support option for client
|
||||||
|
|
Loading…
Reference in a new issue