Rename "Deploy" method to "Init"
There was a bit of confusion between contract deploying and calling "Deploy" method. Also new "Init" method uses generic setter to initialize contract storage.
This commit is contained in:
parent
209740f060
commit
62d5d863f4
1 changed files with 28 additions and 18 deletions
|
@ -30,7 +30,10 @@ const (
|
||||||
tokenHash = "\x3b\x7d\x37\x11\xc6\xf0\xcc\xf9\xb1\xdc\xa9\x03\xd1\xbf\xa1\xd8\x96\xf1\x23\x8c"
|
tokenHash = "\x3b\x7d\x37\x11\xc6\xf0\xcc\xf9\xb1\xdc\xa9\x03\xd1\xbf\xa1\xd8\x96\xf1\x23\x8c"
|
||||||
innerRingCandidateFee = 100 * 1000 * 1000 // 10^8
|
innerRingCandidateFee = 100 * 1000 * 1000 // 10^8
|
||||||
version = 2
|
version = 2
|
||||||
|
innerRingKey = "innerring"
|
||||||
voteKey = "ballots"
|
voteKey = "ballots"
|
||||||
|
candidatesKey = "candidates"
|
||||||
|
cashedChequesKey = "cheques"
|
||||||
blockDiff = 20 // change base on performance evaluation
|
blockDiff = 20 // change base on performance evaluation
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,34 +68,31 @@ func Main(op string, args []interface{}) interface{} {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
switch op {
|
switch op {
|
||||||
case "Deploy":
|
case "Init":
|
||||||
irList := getSerialized(ctx, "InnerRingList").([]node)
|
if storage.Get(ctx, innerRingKey) != nil {
|
||||||
if len(irList) >= 3 {
|
panic("neofs: contract already deployed")
|
||||||
panic("contract already deployed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
irList = []node{}
|
var irList []node
|
||||||
|
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
pub := args[i].([]byte)
|
pub := args[i].([]byte)
|
||||||
irList = append(irList, node{pub: pub})
|
irList = append(irList, node{pub: pub})
|
||||||
}
|
}
|
||||||
|
|
||||||
data := binary.Serialize(irList)
|
// initialize all storage slices
|
||||||
storage.Put(ctx, "InnerRingList", data)
|
setSerialized(ctx, innerRingKey, irList)
|
||||||
|
setSerialized(ctx, voteKey, []ballot{})
|
||||||
|
setSerialized(ctx, candidatesKey, []node{})
|
||||||
|
setSerialized(ctx, cashedChequesKey, []cheque{})
|
||||||
|
|
||||||
data = binary.Serialize([]interface{}{})
|
runtime.Log("neofs: contract initialized")
|
||||||
storage.Put(ctx, "UsedVerifCheckList", data)
|
|
||||||
storage.Put(ctx, "InnerRingCandidates", data)
|
|
||||||
|
|
||||||
data = binary.Serialize([]ballot{})
|
|
||||||
storage.Put(ctx, voteKey, data)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
case "InnerRingList":
|
case "InnerRingList":
|
||||||
irList := getSerialized(ctx, "InnerRingList").([]node)
|
return getInnerRingNodes(ctx)
|
||||||
|
|
||||||
return irList
|
|
||||||
case "InnerRingCandidateRemove":
|
case "InnerRingCandidateRemove":
|
||||||
data := args[0].([]byte) // public key
|
data := args[0].([]byte) // public key
|
||||||
if !runtime.CheckWitness(data) {
|
if !runtime.CheckWitness(data) {
|
||||||
|
@ -308,11 +308,11 @@ func Main(op string, args []interface{}) interface{} {
|
||||||
panic("isInnerRing: incorrect public key")
|
panic("isInnerRing: incorrect public key")
|
||||||
}
|
}
|
||||||
|
|
||||||
irList := getSerialized(ctx, "InnerRingList").([]node)
|
irList := getInnerRingNodes(ctx)
|
||||||
for i := range irList {
|
for i := range irList {
|
||||||
node := irList[i]
|
node := irList[i]
|
||||||
|
|
||||||
if util.Equals(node.pub, key) {
|
if bytesEqual(node.pub, key) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -517,6 +517,16 @@ func setSerialized(ctx storage.Context, key interface{}, value interface{}) {
|
||||||
storage.Put(ctx, key, data)
|
storage.Put(ctx, key, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getInnerRingNodes returns deserialized slice of inner ring nodes from storage.
|
||||||
|
func getInnerRingNodes(ctx storage.Context) []node {
|
||||||
|
data := storage.Get(ctx, innerRingKey)
|
||||||
|
if data != nil {
|
||||||
|
return binary.Deserialize(data.([]byte)).([]node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []node{}
|
||||||
|
}
|
||||||
|
|
||||||
// getInnerRingNodes returns deserialized slice of vote ballots.
|
// getInnerRingNodes returns deserialized slice of vote ballots.
|
||||||
func getBallots(ctx storage.Context) []ballot {
|
func getBallots(ctx storage.Context) []ballot {
|
||||||
data := storage.Get(ctx, voteKey)
|
data := storage.Get(ctx, voteKey)
|
||||||
|
|
Loading…
Reference in a new issue