Add "Bind" and "Unbind" methods

New methods allow to bind and unbind public keys
with the owner, therefore the user can store and
access data with the key, that does not related
to the wallet.
This commit is contained in:
alexvanin 2020-07-16 11:02:19 +03:00
parent f33622d155
commit 8ef70e70d7

View file

@ -35,6 +35,7 @@ const (
candidatesKey = "candidates" candidatesKey = "candidates"
cashedChequesKey = "cheques" cashedChequesKey = "cheques"
blockDiff = 20 // change base on performance evaluation blockDiff = 20 // change base on performance evaluation
publicKeySize = 33
) )
func Main(op string, args []interface{}) interface{} { func Main(op string, args []interface{}) interface{} {
@ -228,6 +229,29 @@ func Main(op string, args []interface{}) interface{} {
runtime.Notify("Cheque", id, user, amount, lockAcc) runtime.Notify("Cheque", id, user, amount, lockAcc)
} }
return true
case "Bind", "Unbind":
if len(args) < 2 {
panic("binding: bad arguments")
}
user := args[0].([]byte)
if !runtime.CheckWitness(user) {
panic("binding: you should be the owner of the wallet")
}
var keys [][]byte
for i := 1; i < len(args); i++ {
pub := args[i].([]byte)
if len(pub) != publicKeySize {
panic("binding: incorrect public key size")
}
keys = append(keys, pub)
}
runtime.Notify(op, user, keys)
return true return true
case "InnerRingUpdate": case "InnerRingUpdate":
data := args[0].([]byte) data := args[0].([]byte)