forked from TrueCloudLab/frostfs-contract
[#15] Update inline docs
Since all contract methods have separated function, method descriptions were moved from global comment section to the function definitions (go-way). Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d75c11c897
commit
9041bb77d4
1 changed files with 41 additions and 28 deletions
|
@ -3,38 +3,32 @@ package smart_contract
|
||||||
/*
|
/*
|
||||||
NeoFS Smart Contract for NEO3.0.
|
NeoFS Smart Contract for NEO3.0.
|
||||||
|
|
||||||
Utility operations, executed once in deploy stage:
|
Utility methods, executed once in deploy stage:
|
||||||
- Init(pubKey, ... ) - setup initial inner ring nodes
|
- Init
|
||||||
- InitConfig(key, value, key, value...) - setup initial NeoFS configuration
|
- InitConfig
|
||||||
|
|
||||||
User operations:
|
User related methods:
|
||||||
- Deposit(script-hash, amount, script-hash(?)) - deposit gas assets to this script-hash address to NeoFS balance
|
- Deposit
|
||||||
- Withdraw(script-hash, amount) - initialize gas asset withdraw from NeoFS balance
|
- Withdraw
|
||||||
- Bind(script-hash, pubKeys...) - bind public key with user's account to use it in NeoFS requests
|
- Bind
|
||||||
- Unbind(script-hash, pubKeys...) - unbind public key from user's account
|
- Unbind
|
||||||
|
|
||||||
Inner ring list operations:
|
Inner ring list related methods:
|
||||||
- InnerRingList() - returns array of inner ring node keys
|
- InnerRingList
|
||||||
- InnerRingCandidates() - returns array of inner ring candidate node keys
|
- InnerRingCandidates
|
||||||
- IsInnerRing(pubKey) - returns 'true' if key is inside of inner ring list
|
- IsInnerRing
|
||||||
- InnerRingCandidateAdd(pubKey) - adds key to the list of inner ring candidates
|
- InnerRingCandidateAdd
|
||||||
- InnerRingCandidateRemove(pubKey) - removes key from the list of inner ring candidates
|
- InnerRingCandidateRemove
|
||||||
- InnerRingUpdate(id, pubKeys...) - updates list of inner ring nodes with provided list of public keys
|
- InnerRingUpdate
|
||||||
|
|
||||||
Config operations:
|
Config methods:
|
||||||
- Config(key) - returns value of NeoFS configuration with key 'key'
|
- Config
|
||||||
- ListConfig() - returns array of all key-value pairs of NeoFS configuration
|
- ListConfig
|
||||||
- SetConfig(id, key, value) - set key-value pair as a NeoFS runtime configuration value
|
- SetConfig
|
||||||
|
|
||||||
Other utility operations:
|
Other utility methods:
|
||||||
- Version - returns contract version
|
- Version
|
||||||
- Cheque(id, script- hash, amount, script-hash) - sends gas assets back to the user if they were successfully
|
- Cheque
|
||||||
locked in NeoFS balance contract
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
- (?) - parameter can be omitted
|
|
||||||
- pubKey - 33 bytes of public key
|
|
||||||
- id - unique byte sequence
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -106,6 +100,7 @@ func init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init set up initial inner ring node keys.
|
||||||
func Init(args []interface{}) bool {
|
func Init(args []interface{}) bool {
|
||||||
if storage.Get(ctx, innerRingKey) != nil {
|
if storage.Get(ctx, innerRingKey) != nil {
|
||||||
panic("neofs: contract already deployed")
|
panic("neofs: contract already deployed")
|
||||||
|
@ -129,14 +124,17 @@ func Init(args []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InnerRingList returns array of inner ring node keys.
|
||||||
func InnerRingList() []node {
|
func InnerRingList() []node {
|
||||||
return getInnerRingNodes(ctx, innerRingKey)
|
return getInnerRingNodes(ctx, innerRingKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidates returns array of inner ring candidate node keys.
|
||||||
func InnerRingCandidates() []node {
|
func InnerRingCandidates() []node {
|
||||||
return getInnerRingNodes(ctx, candidatesKey)
|
return getInnerRingNodes(ctx, candidatesKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateRemove removes key from the list of inner ring candidates.
|
||||||
func InnerRingCandidateRemove(key []byte) bool {
|
func InnerRingCandidateRemove(key []byte) bool {
|
||||||
if !runtime.CheckWitness(key) {
|
if !runtime.CheckWitness(key) {
|
||||||
panic("irCandidateRemove: you should be the owner of the public key")
|
panic("irCandidateRemove: you should be the owner of the public key")
|
||||||
|
@ -159,6 +157,7 @@ func InnerRingCandidateRemove(key []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateAdd adds key to the list of inner ring candidates.
|
||||||
func InnerRingCandidateAdd(key []byte) bool {
|
func InnerRingCandidateAdd(key []byte) bool {
|
||||||
if !runtime.CheckWitness(key) {
|
if !runtime.CheckWitness(key) {
|
||||||
panic("irCandidateAdd: you should be the owner of the public key")
|
panic("irCandidateAdd: you should be the owner of the public key")
|
||||||
|
@ -188,6 +187,7 @@ func InnerRingCandidateAdd(key []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deposit gas assets to this script-hash address in NeoFS balance contract.
|
||||||
func Deposit(from []byte, args []interface{}) bool {
|
func Deposit(from []byte, args []interface{}) bool {
|
||||||
if len(args) < 1 || len(args) > 2 {
|
if len(args) < 1 || len(args) > 2 {
|
||||||
panic("deposit: bad arguments")
|
panic("deposit: bad arguments")
|
||||||
|
@ -223,6 +223,7 @@ func Deposit(from []byte, args []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Withdraw initialize gas asset withdraw from NeoFS balance.
|
||||||
func Withdraw(user []byte, amount int) bool {
|
func Withdraw(user []byte, amount int) bool {
|
||||||
if !runtime.CheckWitness(user) {
|
if !runtime.CheckWitness(user) {
|
||||||
panic("withdraw: you should be the owner of the wallet")
|
panic("withdraw: you should be the owner of the wallet")
|
||||||
|
@ -240,6 +241,8 @@ func Withdraw(user []byte, amount int) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cheque sends gas assets back to the user if they were successfully
|
||||||
|
// locked in NeoFS balance contract.
|
||||||
func Cheque(id, user []byte, amount int, lockAcc []byte) bool {
|
func Cheque(id, user []byte, amount int, lockAcc []byte) bool {
|
||||||
irList := getInnerRingNodes(ctx, innerRingKey)
|
irList := getInnerRingNodes(ctx, innerRingKey)
|
||||||
threshold := len(irList)/3*2 + 1
|
threshold := len(irList)/3*2 + 1
|
||||||
|
@ -280,6 +283,7 @@ func Cheque(id, user []byte, amount int, lockAcc []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bind public key with user's account to use it in NeoFS requests.
|
||||||
func Bind(user []byte, keys []interface{}) bool {
|
func Bind(user []byte, keys []interface{}) bool {
|
||||||
if !runtime.CheckWitness(user) {
|
if !runtime.CheckWitness(user) {
|
||||||
panic("binding: you should be the owner of the wallet")
|
panic("binding: you should be the owner of the wallet")
|
||||||
|
@ -297,6 +301,7 @@ func Bind(user []byte, keys []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unbind public key from user's account
|
||||||
func Unbind(user []byte, keys []interface{}) bool {
|
func Unbind(user []byte, keys []interface{}) bool {
|
||||||
if !runtime.CheckWitness(user) {
|
if !runtime.CheckWitness(user) {
|
||||||
panic("unbinding: you should be the owner of the wallet")
|
panic("unbinding: you should be the owner of the wallet")
|
||||||
|
@ -314,6 +319,8 @@ func Unbind(user []byte, keys []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InnerRingUpdate updates list of inner ring nodes with provided list of
|
||||||
|
// public keys.
|
||||||
func InnerRingUpdate(chequeID []byte, args [][]byte) bool {
|
func InnerRingUpdate(chequeID []byte, args [][]byte) bool {
|
||||||
if len(args) < minInnerRingSize {
|
if len(args) < minInnerRingSize {
|
||||||
panic("irUpdate: bad arguments")
|
panic("irUpdate: bad arguments")
|
||||||
|
@ -386,6 +393,7 @@ loop:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInnerRing returns 'true' if key is inside of inner ring list.
|
||||||
func IsInnerRing(key []byte) bool {
|
func IsInnerRing(key []byte) bool {
|
||||||
if len(key) != publicKeySize {
|
if len(key) != publicKeySize {
|
||||||
panic("isInnerRing: incorrect public key")
|
panic("isInnerRing: incorrect public key")
|
||||||
|
@ -403,10 +411,12 @@ func IsInnerRing(key []byte) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config returns value of NeoFS configuration with provided key.
|
||||||
func Config(key []byte) interface{} {
|
func Config(key []byte) interface{} {
|
||||||
return getConfig(ctx, key)
|
return getConfig(ctx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfig key-value pair as a NeoFS runtime configuration value.
|
||||||
func SetConfig(id, key, val []byte) bool {
|
func SetConfig(id, key, val []byte) bool {
|
||||||
// check if it is inner ring invocation
|
// check if it is inner ring invocation
|
||||||
irList := getInnerRingNodes(ctx, innerRingKey)
|
irList := getInnerRingNodes(ctx, innerRingKey)
|
||||||
|
@ -443,6 +453,7 @@ func SetConfig(id, key, val []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListConfig returns array of all key-value pairs of NeoFS configuration.
|
||||||
func ListConfig() []record {
|
func ListConfig() []record {
|
||||||
var config []record
|
var config []record
|
||||||
|
|
||||||
|
@ -458,6 +469,7 @@ func ListConfig() []record {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitConfig set up initial NeoFS key-value configuration.
|
||||||
func InitConfig(args []interface{}) bool {
|
func InitConfig(args []interface{}) bool {
|
||||||
if getConfig(ctx, candidateFeeConfigKey) != nil {
|
if getConfig(ctx, candidateFeeConfigKey) != nil {
|
||||||
panic("neofs: configuration already installed")
|
panic("neofs: configuration already installed")
|
||||||
|
@ -482,6 +494,7 @@ func InitConfig(args []interface{}) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version of contract.
|
||||||
func Version() int {
|
func Version() int {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue