mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-29 01:12:31 +00:00

* distributed & result msgs * added DistributionResult * added RDDL token conversion methods * set proper validatoraddress within the testcases for e2e/dao * set proper root dir for test cases * fixed some wordings --------- Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/planetmint/planetmint-go/config"
|
|
)
|
|
|
|
type ReissueResult struct {
|
|
Txid string `json:"txid"`
|
|
Vin int `json:"vin"`
|
|
}
|
|
|
|
func ReissueAsset(reissueTx string) (txid string, err error) {
|
|
conf := config.GetConfig()
|
|
cmdArgs := strings.Split(reissueTx, " ")
|
|
cmd := exec.Command("/usr/local/bin/elements-cli", "-rpcpassword="+conf.RPCPassword,
|
|
"-rpcuser="+conf.RPCUser, "-rpcport="+strconv.Itoa(conf.RPCPort), "-rpcconnect="+conf.RPCHost,
|
|
cmdArgs[0], cmdArgs[1], cmdArgs[2])
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err = cmd.Run()
|
|
errstr := stderr.String()
|
|
|
|
if err != nil || len(errstr) > 0 {
|
|
err = errors.New("reissuance of RDDL failed: " + errstr)
|
|
} else {
|
|
var txobj ReissueResult
|
|
err = json.Unmarshal(stdout.Bytes(), &txobj)
|
|
if err == nil {
|
|
txid = txobj.Txid
|
|
}
|
|
}
|
|
return txid, err
|
|
}
|
|
|
|
func DistributeAsset(address string, amount string) (txid string, err error) {
|
|
conf := config.GetConfig()
|
|
cmd := exec.Command("/usr/local/bin/elements-cli", "-rpcpassword="+conf.RPCPassword,
|
|
"-rpcuser="+conf.RPCUser, "-rpcport="+strconv.Itoa(conf.RPCPort), "-rpcconnect="+conf.RPCHost,
|
|
"sendtoaddress", address, amount, "", "", "false", "true", "null", "\"unset\"", "false",
|
|
"\""+conf.ReissuanceAsset+"\"")
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err = cmd.Run()
|
|
errstr := stderr.String()
|
|
|
|
if err != nil || len(errstr) > 0 {
|
|
errormessage := "distribution of RDDL failed for " + address
|
|
err = errors.New(errormessage)
|
|
} else {
|
|
var txobj ReissueResult
|
|
err = json.Unmarshal(stdout.Bytes(), &txobj)
|
|
if err == nil {
|
|
txid = txobj.Txid
|
|
}
|
|
}
|
|
return txid, err
|
|
}
|