Add roles wrapper/tx/query command to basecoin

This commit is contained in:
Ethan Frey
2017-07-19 14:26:40 +02:00
parent 737e3740dd
commit 911dd1423e
12 changed files with 219 additions and 65 deletions
+16 -2
View File
@@ -83,11 +83,11 @@ func GetCertifier() (*certifiers.InquiringCertifier, error) {
return cert, nil
}
// ParseAddress parses an address of form:
// ParseActor parses an address of form:
// [<chain>:][<app>:]<hex address>
// into a basecoin.Actor.
// If app is not specified or "", then assume auth.NameSigs
func ParseAddress(input string) (res basecoin.Actor, err error) {
func ParseActor(input string) (res basecoin.Actor, err error) {
chain, app := "", auth.NameSigs
input = strings.TrimSpace(input)
spl := strings.SplitN(input, ":", 3)
@@ -114,3 +114,17 @@ func ParseAddress(input string) (res basecoin.Actor, err error) {
}
return
}
// ParseActors takes a comma-separated list of actors and parses them into
// a slice
func ParseActors(key string) (signers []basecoin.Actor, err error) {
var act basecoin.Actor
for _, k := range strings.Split(key, ",") {
act, err = ParseActor(k)
if err != nil {
return
}
signers = append(signers, act)
}
return
}
+31
View File
@@ -52,6 +52,37 @@ func GetSignerAct() (res basecoin.Actor) {
return res
}
// DoTx is a helper function for the lazy :)
//
// It uses only public functions and goes through the standard sequence of
// wrapping the tx with middleware layers, signing it, either preparing it,
// or posting it and displaying the result.
//
// If you want a non-standard flow, just call the various functions directly.
// eg. if you already set the middleware layers in your code, or want to
// output in another format.
func DoTx(tx basecoin.Tx) (err error) {
tx, err = Middleware.Wrap(tx)
if err != nil {
return err
}
err = SignTx(tx)
if err != nil {
return err
}
bres, err := PrepareOrPostTx(tx)
if err != nil {
return err
}
if bres == nil {
return nil // successful prep, nothing left to do
}
return OutputTx(bres) // print response of the post
}
// SignTx will validate the tx, and signs it if it is wrapping a Signable.
// Modifies tx in place, and returns an error if it should sign but couldn't
func SignTx(tx basecoin.Tx) error {