示例#1
0
func UpdateNameReg(fileName, hash string) error {
	nodeAddr := os.Getenv("MINTX_NODE_ADDR")
	signAddr := os.Getenv("MINTX_SIGN_ADDR")
	chainID := os.Getenv("MINTX_CHAINID")
	pubkey := strings.TrimSpace(os.Getenv("MINTX_PUBKEY")) //because bash
	addr := ""
	amtS := "10000"
	nonceS := ""
	feeS := "0"
	name := fileName
	data := hash

	log.WithFields(log.Fields{
		"MINTX_NODE_ADDR": nodeAddr,
		"MINTX_CHAINID":   chainID,
		"MINTX_PUBKEY":    pubkey,
		"MINTX_SIGN_ADDR": signAddr,
		"name":            fileName,
		"data":            data,
		"amount":          amtS,
	}).Warn("Building a nameTx:")

	nTx, err := core.Name(nodeAddr, signAddr, pubkey, addr, amtS, nonceS, feeS, name, data)
	if err != nil {
		return fmt.Errorf("corename error: %v\n", err)
	}
	log.WithField("=>", fmt.Sprintf("%v", nTx)).Warn("Success, nameTx created:")

	//sign but don't broadcast

	log.Warn("Signing transaction...")
	_, err = core.SignAndBroadcast(chainID, nodeAddr, signAddr, nTx, true, false, false)
	if err != nil {
		return fmt.Errorf("sign error: %v\n", err)
	}

	n := new(int64)
	w := new(bytes.Buffer)
	wire.WriteBinary(nTx, w, n, &err)

	// post needs to be to toadserver endpoint, which'll
	// eventually route the TX to the nodes using mindy
	txD := bytes.NewReader(w.Bytes())
	//it can also query for the name reg to ensure things are good
	// TODO => modularize
	endpoint := "http://0.0.0.0:11113/" + "receiveNameTx?hash=" + hash
	_, err = http.Post(endpoint, "", txD)
	if err != nil {
		return fmt.Errorf("post error: %v\n", err)
	}
	if err := os.Remove(fileName); err != nil {
		return fmt.Errorf("remove file error: %v\n", err)
	}
	return nil

}
示例#2
0
func cliName(cmd *cobra.Command, args []string) {
	if dataFlag != "" && dataFileFlag != "" {
		common.Exit(fmt.Errorf("Please specify only one of --data and --data-file"))
	}
	data := dataFlag
	if dataFlag == "" && dataFileFlag != "" {
		b, err := ioutil.ReadFile(dataFileFlag)
		common.IfExit(err)
		data = string(b)
	}
	tx, err := core.Name(nodeAddrFlag, signAddrFlag, pubkeyFlag, addrFlag, amtFlag, nonceFlag, feeFlag, nameFlag, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainidFlag, nodeAddrFlag, signAddrFlag, tx, signFlag, broadcastFlag, waitFlag))
}
示例#3
0
文件: cli.go 项目: alist/mint-client
func cliName(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, amtS, nonceS, feeS, addr := c.String("pubkey"), c.String("amt"), c.String("nonce"), c.String("fee"), c.String("addr")

	if c.IsSet("data") && c.IsSet("data-file") {
		common.Exit(fmt.Errorf("Please specify only one of --data and --data-file"))
	}
	name, data, dataFile := c.String("name"), c.String("data"), c.String("data-file")
	if data == "" && dataFile != "" {
		b, err := ioutil.ReadFile(dataFile)
		common.IfExit(err)
		data = string(b)
	}
	tx, err := core.Name(nodeAddr, pubkey, addr, amtS, nonceS, feeS, name, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}