@@ -13,6 +13,7 @@ import (
13
13
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
14
14
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
15
15
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
16
+ "github.com/nspcc-dev/neo-go/pkg/smartcontract"
16
17
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
17
18
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
18
19
"github.com/nspcc-dev/neo-go/pkg/util"
@@ -25,6 +26,12 @@ const (
25
26
methodUpdate = "update"
26
27
)
27
28
29
+ const (
30
+ _ uint8 = iota
31
+ witnessAlphabet
32
+ witnessAlphabetAndCommittee
33
+ )
34
+
28
35
// syncNeoFSContractPrm groups parameters of syncNeoFSContract.
29
36
type syncNeoFSContractPrm struct {
30
37
logger * zap.Logger
@@ -56,10 +63,12 @@ type syncNeoFSContractPrm struct {
56
63
// if set, syncNeoFSContract attempts to deploy the contract when it's
57
64
// missing on the chain
58
65
tryDeploy bool
59
- // is contract must be deployed by the committee
60
- committeeDeployRequired bool
61
- // additional allowed contracts to be added to the NNS one if committeeDeployRequired
62
- extraCommitteeDeployAllowedContracts []util.Uint160
66
+ // 0: committee witness is not needed
67
+ // witnessAlphabet: committee 2/3n+1 with allowed alphabetDeployAllowedContracts
68
+ // witnessAlphabetAndCommittee: witnessAlphabet + committee n/2+1 with allowed NNS contract calls
69
+ deployWitness uint8
70
+ // contracts that are allowed to be called for the Alphabet-witnessed deployment
71
+ alphabetDeployAllowedContracts []util.Uint160
63
72
64
73
// optional constructor of extra arguments to be passed into method deploying
65
74
// the contract. If returns both nil, no data is passed (noExtraDeployArgs can
@@ -126,11 +135,46 @@ func syncNeoFSContract(ctx context.Context, prm syncNeoFSContractPrm) (util.Uint
126
135
Sender () util.Uint160
127
136
}
128
137
var managementContract * management.Contract
129
- if prm .committeeDeployRequired {
130
- deployCommitteeActor , err := newCommitteeNotaryActorWithCustomCommitteeSigner (prm .blockchain , prm .localAcc , prm .committee , func (s * transaction.Signer ) {
131
- s .Scopes = transaction .CustomContracts
132
- s .AllowedContracts = append (prm .extraCommitteeDeployAllowedContracts , prm .nnsContract )
133
- })
138
+ if prm .deployWitness > 0 {
139
+ if prm .deployWitness != witnessAlphabet && prm .deployWitness != witnessAlphabetAndCommittee {
140
+ panic (fmt .Sprintf ("unexpected deploy witness mode value %v" , prm .deployWitness ))
141
+ }
142
+
143
+ committeeDefaultMultiSigAcc := wallet .NewAccountFromPrivateKey (prm .localAcc .PrivateKey ())
144
+ err := committeeDefaultMultiSigAcc .ConvertMultisig (smartcontract .GetDefaultHonestNodeCount (len (prm .committee )), prm .committee )
145
+ if err != nil {
146
+ return util.Uint160 {}, fmt .Errorf ("compose committee default multi-signature account: %w" , err )
147
+ }
148
+
149
+ signers := make ([]actor.SignerAccount , 2 , 3 )
150
+ // payer
151
+ signers [0 ].Account = prm .localAcc
152
+ signers [0 ].Signer .Account = prm .localAcc .ScriptHash ()
153
+ signers [0 ].Signer .Scopes = transaction .None
154
+ // Alphabet
155
+ signers [1 ].Account = committeeDefaultMultiSigAcc
156
+ signers [1 ].Signer .Account = committeeDefaultMultiSigAcc .ScriptHash ()
157
+ signers [1 ].Signer .Scopes = transaction .CustomContracts
158
+ signers [1 ].Signer .AllowedContracts = prm .alphabetDeployAllowedContracts
159
+
160
+ if prm .deployWitness == witnessAlphabetAndCommittee {
161
+ committeeMajorityMultiSigAcc := wallet .NewAccountFromPrivateKey (prm .localAcc .PrivateKey ())
162
+ err := committeeMajorityMultiSigAcc .ConvertMultisig (smartcontract .GetMajorityHonestNodeCount (len (prm .committee )), prm .committee )
163
+ if err != nil {
164
+ return util.Uint160 {}, fmt .Errorf ("compose committee majority multi-signature account: %w" , err )
165
+ }
166
+
167
+ signers = append (signers , actor.SignerAccount {
168
+ Signer : transaction.Signer {
169
+ Account : committeeMajorityMultiSigAcc .ScriptHash (),
170
+ Scopes : transaction .CustomContracts ,
171
+ AllowedContracts : []util.Uint160 {prm .nnsContract },
172
+ },
173
+ Account : committeeMajorityMultiSigAcc ,
174
+ })
175
+ }
176
+
177
+ deployCommitteeActor , err := notary .NewActor (prm .blockchain , signers , prm .localAcc )
134
178
if err != nil {
135
179
return util.Uint160 {}, fmt .Errorf ("create Notary service client sending deploy transactions to be signed by the committee: %w" , err )
136
180
}
@@ -226,7 +270,7 @@ func syncNeoFSContract(ctx context.Context, prm syncNeoFSContractPrm) (util.Uint
226
270
nefCp := prm .localNEF
227
271
manifestCp := prm .localManifest
228
272
229
- if prm .committeeDeployRequired {
273
+ if prm .deployWitness > 0 {
230
274
l .Info ("contract requires committee witness for deployment, sending Notary request..." )
231
275
232
276
mainTxID , fallbackTxID , vub , err := prm .committeeLocalActor .Notarize (managementContract .DeployTransaction (& nefCp , & manifestCp , extraDeployArgs ))
0 commit comments