planetmint-go/util/elementsd_connector.go
Julian Strobl 6472d7693f
[ci] Add nosnakecase to golangci-lint (#161)
Golang uses:

- Camel Case for variable names, e.g. `firstName`
- Camel Case for private function names, e.g. `getFirstName`
- Pascal Case for public function names, e.g. `GetFirstName`

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2023-10-20 14:09:07 +02:00

44 lines
937 B
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")
} else {
var txobj ReissueResult
err = json.Unmarshal(stdout.Bytes(), &txobj)
if err == nil {
txid = txobj.Txid
}
}
return txid, err
}