github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/deploy/def/jobs.go (about) 1 package def 2 3 import ( 4 "fmt" 5 "regexp" 6 7 validation "github.com/go-ozzo/ozzo-validation" 8 "github.com/go-ozzo/ozzo-validation/is" 9 "github.com/hyperledger/burrow/deploy/def/rule" 10 "github.com/hyperledger/burrow/execution/evm/abi" 11 ) 12 13 // ------------------------------------------------------------------------ 14 // Proposal Jobs 15 // ------------------------------------------------------------------------ 16 17 type Proposal struct { 18 // (Optional), address of the account that signs the proposal or votes for the proposal 19 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 20 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 21 // know what you're doing) 22 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 23 // (Required), address of the account used for serialising proposals, the proposals system account 24 ProposalAddress string `mapstructure:"proposaladdress" json:"proposaladdress" yaml:"proposaladdress" toml:"proposaladdress"` 25 // (Optional), sequence of the ProposalAddress 26 ProposalSequence string `mapstructure:"proposalsequence" json:"proposalsequence" yaml:"proposalsequence" toml:"proposalsequence"` 27 // (Optional) 28 VotingPower string `mapstructure:"votingpower" json:"votingpower" yaml:"votingpower" toml:"votingpower"` 29 // (Required) the name of the proposal 30 Name string `mapstructure:"name" json:"name" yaml:"name" toml:"name"` 31 // (Required) the description of the proposal 32 Description string `mapstructure:"description" json:"description" yaml:"description" toml:"description"` 33 // (Required) the file path of the sub yaml to run 34 Jobs []*Job `mapstructure:"jobs" json:"jobs" yaml:"jobs" toml:"jobs"` 35 } 36 37 func (job *Proposal) Validate() error { 38 return validation.ValidateStruct(job, 39 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 40 validation.Field(&job.VotingPower, rule.Uint64OrPlaceholder), 41 validation.Field(&job.Name, validation.Required), 42 validation.Field(&job.Description, validation.Required), 43 validation.Field(&job.Jobs, validation.Required), 44 ) 45 } 46 47 // ------------------------------------------------------------------------ 48 // Meta Jobs 49 // ------------------------------------------------------------------------ 50 51 // Used in the Target of UpdateAccount to determine whether to create a new account, e.g. new() or new(key1,ed25519) 52 var NewKeyRegex = regexp.MustCompile(`new\((?P<keyName>[[:alnum:]]+)?(,(?P<curveType>[[:alnum:]]+))?\)`) 53 54 func KeyNameCurveType(newKeyMatch []string) (keyName, curveType string) { 55 for i, name := range NewKeyRegex.SubexpNames() { 56 switch name { 57 case "keyName": 58 keyName = newKeyMatch[i] 59 case "curveType": 60 curveType = newKeyMatch[i] 61 } 62 } 63 return 64 } 65 66 type Meta struct { 67 // (Required) the file path of the sub yaml to run 68 File string `mapstructure:"file" json:"file" yaml:"file" toml:"file"` 69 Playbook *Playbook `json:"-" yaml:"-" toml:"-"` 70 } 71 72 func (job *Meta) Validate() error { 73 return validation.ValidateStruct(job, 74 validation.Field(&job.File, validation.Required), 75 ) 76 } 77 78 // ------------------------------------------------------------------------ 79 // Governance Jobs 80 // ------------------------------------------------------------------------ 81 82 type PermissionString string 83 84 func (ps PermissionString) Validate() error { 85 return rule.PermissionOrPlaceholder.Validate(ps) 86 } 87 88 // UpdateAccount updates an account by overwriting the given values, where values are omitted the existing values 89 // are preserved. Currently requires Root permission on Source account 90 type UpdateAccount struct { 91 // (Optional, if account job or global account set) address of the account from which to send (the 92 // public key for the account must be available to burrow keys) 93 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 94 // (Required) The target account that will be governed - either an address or public key (its type will be determined by it's length) 95 // if altering power then either a public key must be provided or the requisite public key associated with the address 96 // must be available in an connected keys Signer 97 Target string `mapstructure:"target" json:"target" yaml:"target" toml:"target"` 98 // (Optional) the Tendermint validator power to set for this account 99 Power string `mapstructure:"power" json:"power" yaml:"power" toml:"power"` 100 // (Optional) The Burrow native token balance to set for this account 101 Native string `mapstructure:"native" json:"native" yaml:"native" toml:"native"` 102 // (Optional) the permissions to set for this account 103 Permissions []PermissionString `mapstructure:"permissions" json:"permissions" yaml:"permissions" toml:"permissions"` 104 // (Optional) the account permission roles to set for this account 105 Roles []string `mapstructure:"roles" json:"roles" yaml:"roles" toml:"roles"` 106 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 107 // know what you're doing) 108 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 109 } 110 111 func (job *UpdateAccount) Validate() error { 112 return validation.ValidateStruct(job, 113 validation.Field(&job.Target, validation.Required, rule.Or(rule.Placeholder, is.Hexadecimal, 114 validation.Match(NewKeyRegex))), 115 validation.Field(&job.Permissions), 116 validation.Field(&job.Power, rule.Uint64OrPlaceholder), 117 validation.Field(&job.Native, rule.Uint64OrPlaceholder), 118 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 119 ) 120 } 121 122 // ------------------------------------------------------------------------ 123 // Util Jobs 124 // ------------------------------------------------------------------------ 125 126 type Account struct { 127 // (Required) address of the account which should be used as the default (if source) is 128 // not given for future transactions. Will make sure the burrow keys has the public key 129 // for the account. Generally account should be the first job called unless it is used 130 // via a flag or environment variables to establish what default to use. 131 Address string `mapstructure:"address" json:"address" yaml:"address" toml:"address"` 132 } 133 134 func (job *Account) Validate() error { 135 return validation.ValidateStruct(job, 136 validation.Field(&job.Address, validation.Required), 137 ) 138 } 139 140 type Set struct { 141 // (Required) value which should be saved along with the jobName (which will be the key) 142 // this is useful to set variables which can be used throughout the jobs definition file (deploy.yaml). 143 // It should be noted that arrays and bools must be defined using strings as such "[1,2,3]" 144 // if they are intended to be used further in a assert job. 145 Value string `mapstructure:"val" json:"val" yaml:"val" toml:"val"` 146 } 147 148 func (job *Set) Validate() error { 149 return validation.ValidateStruct(job, 150 validation.Field(&job.Value, validation.Required), 151 ) 152 } 153 154 // ------------------------------------------------------------------------ 155 // Transaction Jobs 156 // ------------------------------------------------------------------------ 157 158 type Send struct { 159 // (Optional, if account job or global account set) address of the account from which to send (the 160 // public key for the account must be available to burrow keys) 161 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 162 // (Required) address of the account to send the tokens 163 Destination string `mapstructure:"destination" json:"destination" yaml:"destination" toml:"destination"` 164 // (Required) amount of tokens to send from the `source` to the `destination` 165 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 166 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 167 // know what you're doing) 168 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 169 } 170 171 func (job *Send) Validate() error { 172 return validation.ValidateStruct(job, 173 validation.Field(&job.Destination, validation.Required), 174 validation.Field(&job.Amount, rule.Uint64OrPlaceholder), 175 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 176 ) 177 } 178 179 type Bond struct { 180 // (Optional, if account job or global account set) address of the account from which to bond (the 181 // public key for the account must be available to burrow keys) 182 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 183 // (Required) the Tendermint validator power to claim 184 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 185 // (Optional, advanced only) sequence to use when burrow keys signs the transaction 186 // (do not use unless you know what you're doing) 187 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 188 } 189 190 func (job *Bond) Validate() error { 191 return validation.ValidateStruct(job, 192 validation.Field(&job.Amount, validation.Required), 193 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 194 ) 195 } 196 197 type Unbond struct { 198 // (Optional, if account job or global account set) address of the validator to unbond (the 199 // public key for the validator must be available to burrow keys) 200 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 201 // (Required) the Tendermint validator power to unclaim 202 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 203 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 204 // know what you're doing) 205 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 206 } 207 208 func (job *Unbond) Validate() error { 209 return validation.ValidateStruct(job, 210 validation.Field(&job.Amount, validation.Required), 211 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 212 ) 213 } 214 215 type RegisterName struct { 216 // (Optional, if account job or global account set) address of the account from which to send (the 217 // public key for the account must be available to burrow keys) 218 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 219 // (Required - unless providing data file) name which will be registered 220 Name string `mapstructure:"name" json:"name" yaml:"name" toml:"name"` 221 // (Optional, if data_file is used; otherwise required) data which will be stored at the `name` key 222 Data string `mapstructure:"data" json:"data" yaml:"data" toml:"data"` 223 // (Optional) csv file in the form (name,data[,amount]) which can be used to bulk register names 224 DataFile string `mapstructure:"data_file" json:"data_file" yaml:"data_file" toml:"data_file"` 225 // (Optional) amount of blocks which the name entry will be reserved for the registering user 226 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 227 // (Optional) validators' fee 228 Fee string `mapstructure:"fee" json:"fee" yaml:"fee" toml:"fee"` 229 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 230 // know what you're doing) 231 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 232 } 233 234 func (job *RegisterName) Validate() error { 235 return validation.ValidateStruct(job, 236 validation.Field(&job.Amount, rule.Uint64OrPlaceholder), 237 validation.Field(&job.Fee, rule.Uint64OrPlaceholder), 238 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 239 ) 240 } 241 242 type Permission struct { 243 // (Optional, if account job or global account set) address of the account from which to send (the 244 // public key for the account must be available to burrow keys) 245 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 246 // (Required) actions must be in the set ["set_base", "unset_base", "set_global", "add_role" "rm_role"] 247 Action string `mapstructure:"action" json:"action" yaml:"action" toml:"action"` 248 // (Required, unless add_role or rm_role action selected) the name of the permission flag which is to 249 // be updated 250 Permission string `mapstructure:"permission" json:"permission" yaml:"permission" toml:"permission"` 251 // (Required) the value of the permission or role which is to be updated 252 Value string `mapstructure:"value" json:"value" yaml:"value" toml:"value"` 253 // (Required) the target account which is to be updated 254 Target string `mapstructure:"target" json:"target" yaml:"target" toml:"target"` 255 // (Required, if add_role or rm_role action selected) the role which should be given to the account 256 Role string `mapstructure:"role" json:"role" yaml:"role" toml:"role"` 257 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 258 // know what you're doing) 259 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 260 } 261 262 func (job *Permission) Validate() error { 263 return validation.ValidateStruct(job, 264 validation.Field(&job.Value, validation.In("true", "false", "")), 265 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 266 ) 267 } 268 269 type Identify struct { 270 // (Optional, if account job or global account set) address of the account from which to identify (the 271 // public key for the account must be available to burrow keys) 272 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 273 // (Required) file containing the tendermint node to identify as 274 NodeKey string `mapstructure:"nodekey" json:"nodekey" yaml:"nodekey" toml:"nodekey"` 275 // (Required) publically available network address 276 NetAddress string `mapstructure:"netaddress" json:"netaddress" yaml:"netaddress" toml:"netaddress"` 277 // (Optional) publically available network moniker 278 Moniker string `mapstructure:"moniker" json:"moniker" yaml:"moniker" toml:"moniker"` 279 280 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 281 // know what you're doing) 282 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 283 } 284 285 func (job *Identify) Validate() error { 286 return validation.ValidateStruct(job, 287 validation.Field(&job.NodeKey, validation.Required), 288 validation.Field(&job.NetAddress, validation.Required), 289 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 290 ) 291 } 292 293 // ------------------------------------------------------------------------ 294 // Contracts Jobs 295 // ------------------------------------------------------------------------ 296 297 type PackageDeploy struct { 298 // TODO 299 } 300 301 type Build struct { 302 // (Required) the filepath to the contract file. this should be relative to the current path **or** 303 // relative to the contracts path established via the --dir. 304 // If contract has a "bin" file extension then it will not be sent to the 305 // compilers but rather will just be sent to the chain. Note, if you use a "call" job after deploying 306 // a binary contract then you will be **required** to utilize an abi field in the call job. 307 Contract string `mapstructure:"contract" json:"contract" yaml:"contract" toml:"contract"` 308 // (Optional) where to save the result of the compilation 309 BinPath string `mapstructure:"binpath" json:"binpath" yaml:"binpath" toml:"binpath"` 310 // (Optional) the name of contract to instantiate (it has to be one of the contracts present) 311 // in the file defined in Contract above. 312 // When none is provided, the system will choose the contract with the same name as that file. 313 // use "all" to override and deploy all contracts in order. if "all" is selected the result 314 // of the job will default to the address of the contract which was deployed that matches 315 // the name of the file (or the last one deployed if there are no matching names; not the "last" 316 // one deployed" strategy is non-deterministic and should not be used). 317 Instance string `mapstructure:"instance" json:"instance" yaml:"instance" toml:"instance"` 318 // (Optional) Path to store an extra copy of the bin file 319 Store string `mapstructure:"store" json:"store" yaml:"store" toml:"store"` 320 // (Optional) Use solang to compile to wasm 321 Wasm bool `mapstructure:"wasm" json:"wasm" yaml:"wasm" toml:"wasm"` 322 } 323 324 func (job *Build) Validate() error { 325 return validation.ValidateStruct(job, 326 validation.Field(&job.Contract, validation.Required), 327 ) 328 } 329 330 type Deploy struct { 331 // (Optional, if account job or global account set) address of the account from which to send (the 332 // public key for the account must be available to burrow keys) 333 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 334 // (Required) the filepath to the contract file. this should be relative to the current path **or** 335 // relative to the contracts path established via the --dir. 336 // If contract has a "bin" file extension then it will not be sent to the 337 // compilers but rather will just be sent to the chain. Note, if you use a "call" job after deploying 338 // a binary contract then you will be **required** to utilize an abi field in the call job. 339 Contract string `mapstructure:"contract" json:"contract" yaml:"contract" toml:"contract"` 340 // (Optional) the name of contract to instantiate (it has to be one of the contracts present) 341 // in the file defined in Contract above. 342 // When none is provided, the system will choose the contract with the same name as that file. 343 // use "all" to override and deploy all contracts in order. if "all" is selected the result 344 // of the job will default to the address of the contract which was deployed that matches 345 // the name of the file (or the last one deployed if there are no matching names; not the "last" 346 // one deployed" strategy is non-deterministic and should not be used). 347 Instance string `mapstructure:"instance" json:"instance" yaml:"instance" toml:"instance"` 348 // (Optional) the file path for the linkReferences for contract 349 Libraries string `mapstructure:"libraries" json:"libraries" yaml:"libraries" toml:"libraries"` 350 // (Optional) TODO: additional arguments to send along with the contract code 351 Data interface{} `mapstructure:"data" json:"data" yaml:"data" toml:"data"` 352 // (Optional) amount of tokens to send to the contract which will (after deployment) reside in the 353 // contract's account 354 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 355 // (Optional) validators' fee 356 Fee string `mapstructure:"fee" json:"fee" yaml:"fee" toml:"fee"` 357 // (Optional) amount of gas which should be sent along with the contract deployment transaction 358 Gas string `mapstructure:"gas" json:"gas" yaml:"gas" toml:"gas"` 359 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 360 // know what you're doing) 361 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 362 // (Optional) todo 363 Variables []*abi.Variable 364 // (Optional) Path to store an extra copy of the bin file 365 Store string `mapstructure:"store" json:"store" yaml:"store" toml:"store"` 366 // (Optional) Use solang to compile to wasm 367 Wasm bool `mapstructure:"wasm" json:"wasm" yaml:"wasm" toml:"wasm"` 368 } 369 370 func (job *Deploy) Validate() error { 371 return validation.ValidateStruct(job, 372 validation.Field(&job.Contract, validation.Required), 373 validation.Field(&job.Amount, rule.Uint64OrPlaceholder), 374 validation.Field(&job.Fee, rule.Uint64OrPlaceholder), 375 validation.Field(&job.Gas, rule.Uint64OrPlaceholder), 376 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 377 ) 378 } 379 380 type Call struct { 381 // (Optional, if account job or global account set) address of the account from which to send (the 382 // public key for the account must be available to burrow keys) 383 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 384 // (Required) address of the contract which should be called 385 Destination string `mapstructure:"destination" json:"destination" yaml:"destination" toml:"destination"` 386 // (Required unless testing fallback function) function inside the contract to be called 387 Function string `mapstructure:"function" json:"function" yaml:"function" toml:"function"` 388 // (Optional) data which should be called. will use the monax-abi tooling under the hood to formalize the 389 // transaction 390 Data interface{} `mapstructure:"data" json:"data" yaml:"data" toml:"data"` 391 // (Optional) amount of tokens to send to the contract 392 Amount string `mapstructure:"amount" json:"amount" yaml:"amount" toml:"amount"` 393 // (Optional) validators' fee 394 Fee string `mapstructure:"fee" json:"fee" yaml:"fee" toml:"fee"` 395 // (Optional) amount of gas which should be sent along with the call transaction 396 Gas string `mapstructure:"gas" json:"gas" yaml:"gas" toml:"gas"` 397 // (Optional, advanced only) sequence to use when burrow keys signs the transaction (do not use unless you 398 // know what you're doing) 399 Sequence string `mapstructure:"sequence" json:"sequence" yaml:"sequence" toml:"sequence"` 400 // (Optional) location of the bin file to use (can be relative path or in bin path) 401 // deployed contracts save ABI artifacts in the bin folder as *both* the name of the contract 402 // and the address where the contract was deployed to 403 Bin string `mapstructure:"bin" json:"bin" yaml:"bin" toml:"bin"` 404 // (Optional) by default the call job will "store" the return from the contract as the 405 // result of the job. If you would like to store the transaction hash instead of the 406 // return from the call job as the result of the call job then select "tx" on the save 407 // variable. Anything other than "tx" in this field will use the default. 408 Save string `mapstructure:"save" json:"save" yaml:"save" toml:"save"` 409 // (Optional) the call job's returned variables 410 Variables []*abi.Variable 411 } 412 413 // TODO: maybe do for others... 414 func (job *Call) String() string { 415 return fmt.Sprintf("%#v", job) 416 } 417 418 func (job *Call) Validate() error { 419 return validation.ValidateStruct(job, 420 validation.Field(&job.Destination, validation.Required), 421 validation.Field(&job.Amount, rule.Uint64OrPlaceholder), 422 validation.Field(&job.Fee, rule.Uint64OrPlaceholder), 423 validation.Field(&job.Gas, rule.Uint64OrPlaceholder), 424 validation.Field(&job.Sequence, rule.Uint64OrPlaceholder), 425 ) 426 } 427 428 // ------------------------------------------------------------------------ 429 // State Jobs 430 // ------------------------------------------------------------------------ 431 432 type DumpState struct { 433 WithValidators bool `mapstructure:"include-validators" json:"include-validators" yaml:"include-validators" toml:"include-validators"` 434 ToIPFS bool `mapstructure:"to-ipfs" json:"to-ipfs" yaml:"to-ipfs" toml:"to-ipfs"` 435 ToFile bool `mapstructure:"to-file" json:"to-file" yaml:"to-file" toml:"to-file"` 436 IPFSHost string `mapstructure:"ipfs-host" json:"ipfs-host" yaml:"ipfs-host" toml:"ipfs-host"` 437 FilePath string `mapstructure:"file" json:"file" yaml:"file" toml:"file"` 438 } 439 440 func (job *DumpState) Validate() error { 441 // TODO: write validation logic 442 return nil 443 } 444 445 type RestoreState struct { 446 FromIPFS bool `mapstructure:"from-ipfs" json:"from-ipfs" yaml:"from-ipfs" toml:"from-ipfs"` 447 FromFile bool `mapstructure:"from-file" json:"from-file" yaml:"from-file" toml:"from-file"` 448 IPFSHost string `mapstructure:"ipfs-host" json:"ipfs-host" yaml:"ipfs-host" toml:"ipfs-host"` 449 FilePath string `mapstructure:"file" json:"file" yaml:"file" toml:"file"` 450 } 451 452 func (job *RestoreState) Validate() error { 453 // TODO: write validation logic 454 return nil 455 } 456 457 // ------------------------------------------------------------------------ 458 // Testing Jobs 459 // ------------------------------------------------------------------------ 460 461 // aka. Simulated Call. 462 type QueryContract struct { 463 // (Optional, if account job or global account set) address of the account from which to send (the 464 // public key for the account must be available to burrow keys) 465 Source string `mapstructure:"source" json:"source" yaml:"source" toml:"source"` 466 // (Required) address of the contract which should be called 467 Destination string `mapstructure:"destination" json:"destination" yaml:"destination" toml:"destination"` 468 // (Required) data which should be called. will use the monax-abi tooling under the hood to formalize the 469 // transaction. QueryContract will usually be used with "accessor" functions in contracts 470 Function string `mapstructure:"function" json:"function" yaml:"function" toml:"function"` 471 // (Optional) data to be used in the function arguments. Will use the monax-abi tooling under the hood to formalize the 472 // transaction. 473 Data interface{} `mapstructure:"data" json:"data" yaml:"data" toml:"data"` 474 // (Optional) location of the bin file to use (can be relative path or in abi path) 475 // deployed contracts save ABI artifacts in the abi folder as *both* the name of the contract 476 // and the address where the contract was deployed to 477 Bin string `mapstructure:"bin" json:"bin" yaml:"bin" toml:"bin"` 478 479 Variables []*abi.Variable 480 } 481 482 func (job *QueryContract) Validate() error { 483 return validation.ValidateStruct(job, 484 validation.Field(&job.Destination, validation.Required), 485 ) 486 } 487 488 type QueryAccount struct { 489 // (Required) address of the account which should be queried 490 Account string `mapstructure:"account" json:"account" yaml:"account" toml:"account"` 491 // (Required) field which should be queried. If users are trying to query the permissions of the 492 // account one can get either the `permissions.base` which will return the base permission of the 493 // account, or one can get the `permissions.set` which will return the setBit of the account. 494 Field string `mapstructure:"field" json:"field" yaml:"field" toml:"field"` 495 } 496 497 func (job *QueryAccount) Validate() error { 498 return validation.ValidateStruct(job, 499 validation.Field(&job.Account, validation.Required), 500 validation.Field(&job.Field, validation.Required), 501 ) 502 } 503 504 type QueryName struct { 505 // (Required) name which should be queried 506 Name string `mapstructure:"name" json:"name" yaml:"name" toml:"name"` 507 // (Required) field which should be quiried (generally will be "data" to get the registered "name") 508 Field string `mapstructure:"field" json:"field" yaml:"field" toml:"field"` 509 } 510 511 func (job *QueryName) Validate() error { 512 return validation.ValidateStruct(job, 513 validation.Field(&job.Name, validation.Required), 514 validation.Field(&job.Field, validation.Required), 515 ) 516 } 517 518 type QueryVals struct { 519 // (Required) should be of the set ["bonded_validators" or "unbonding_validators"] and it will 520 // return a comma separated listing of the addresses which fall into one of those categories 521 Query string `mapstructure:"field" json:"field" yaml:"field" toml:"field"` 522 } 523 524 func (job *QueryVals) Validate() error { 525 return validation.ValidateStruct(job, 526 validation.Field(&job.Query, validation.Required), 527 ) 528 } 529 530 type Assert struct { 531 // (Required) key which should be used for the assertion. This is usually known as the "expected" 532 // value in most testing suites 533 Key string `mapstructure:"key" json:"key" yaml:"key" toml:"key"` 534 // (Required) must be of the set ["eq", "ne", "ge", "gt", "le", "lt", "==", "!=", ">=", ">", "<=", "<"] 535 // establishes the relation to be tested by the assertion. If a strings key:value pair is being used 536 // only the equals or not-equals relations may be used as the key:value will try to be converted to 537 // ints for the remainder of the relations. if strings are passed to them then `monax pkgs do` will return an 538 // error 539 Relation string `mapstructure:"relation" json:"relation" yaml:"relation" toml:"relation"` 540 // (Required) value which should be used for the assertion. This is usually known as the "given" 541 // value in most testing suites. Generally it will be a variable expansion from one of the query 542 // jobs. 543 Value string `mapstructure:"val" json:"val" yaml:"val" toml:"val"` 544 } 545 546 func (job *Assert) Validate() error { 547 return validation.ValidateStruct(job, 548 validation.Field(&job.Relation, validation.Required, rule.Relation), 549 ) 550 }