Example #1
0
func Broadcast(tx types.Tx, broadcastRPC string) (*rtypes.Receipt, error) {
	client := cclient.NewClient(broadcastRPC, "JSONRPC")
	rec, err := client.BroadcastTx(tx)
	if err != nil {
		return nil, err
	}
	return &rec.Receipt, nil
}
Example #2
0
func before(cmd *cobra.Command, args []string) {
	if !strings.HasPrefix(nodeAddrFlag, "http://") {
		nodeAddrFlag = "http://" + nodeAddrFlag
	}
	if !strings.HasSuffix(nodeAddrFlag, "/") {
		nodeAddrFlag += "/"
	}

	client = cclient.NewClient(nodeAddrFlag, REQUEST_TYPE)
}
Example #3
0
func checkCommon(nodeAddr, pubkey, addr, amtS, nonceS string) (pub account.PubKey, addrBytes []byte, amt int64, nonce int64, err error) {
	if amtS == "" {
		err = fmt.Errorf("input must specify an amount with the --amt flag")
		return
	}

	if pubkey == "" && addr == "" {
		err = fmt.Errorf("at least one of --pubkey or --addr must be given")
		return
	}

	pubKeyBytes, err := hex.DecodeString(pubkey)
	if err != nil {
		err = fmt.Errorf("pubkey is bad hex: %v", err)
		return
	}

	addrBytes, err = hex.DecodeString(addr)
	if err != nil {
		err = fmt.Errorf("addr is bad hex: %v", err)
		return
	}

	amt, err = strconv.ParseInt(amtS, 10, 64)
	if err != nil {
		err = fmt.Errorf("amt is misformatted: %v", err)
	}

	if len(pubKeyBytes) > 0 {
		var pubArray [32]byte
		copy(pubArray[:], pubKeyBytes)
		pub = account.PubKeyEd25519(pubArray)
		addrBytes = pub.Address()
	}

	if nonceS == "" {
		if nodeAddr == "" {
			err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or MINTX_NODE_ADDR) to fetch the nonce from a node")
			return
		}

		// fetch nonce from node
		client := cclient.NewClient(nodeAddr, "HTTP")
		ac, err2 := client.GetAccount(addrBytes)
		if err2 != nil {
			err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error())
			return
		}
		if ac == nil || ac.Account == nil {
			err = fmt.Errorf("unknown account %X", addrBytes)
			return
		}
		nonce = int64(ac.Account.Sequence) + 1
	} else {
		nonce, err = strconv.ParseInt(nonceS, 10, 64)
		if err != nil {
			err = fmt.Errorf("nonce is misformatted: %v", err)
			return
		}
	}

	return
}
Example #4
0
func checkCommon(nodeAddr, signAddr, pubkey, addr, amtS, nonceS string) (pub account.PubKey, amt int64, nonce int64, err error) {
	if amtS == "" {
		err = fmt.Errorf("input must specify an amount with the --amt flag")
		return
	}

	var pubKeyBytes []byte
	if pubkey == "" && addr == "" {
		err = fmt.Errorf("at least one of --pubkey or --addr must be given")
		return
	} else if pubkey != "" {
		if addr != "" {
			// NOTE: if --addr given byt MINTX_PUBKEY is set, the pubkey still wins
			// TODO: fix this
			logger.Errorln("you have specified both a pubkey and an address. the pubkey takes precedent")
		}
		pubKeyBytes, err = hex.DecodeString(pubkey)
		if err != nil {
			err = fmt.Errorf("pubkey is bad hex: %v", err)
			return
		}
	} else {
		// grab the pubkey from eris-keys
		pubKeyBytes, err = Pub(addr, signAddr)
		if err != nil {
			err = fmt.Errorf("failed to fetch pubkey for address (%s): %v", addr, err)
			return
		}

	}

	if len(pubKeyBytes) == 0 {
		err = fmt.Errorf("Error resolving public key")
		return
	}

	amt, err = strconv.ParseInt(amtS, 10, 64)
	if err != nil {
		err = fmt.Errorf("amt is misformatted: %v", err)
	}

	var pubArray [32]byte
	copy(pubArray[:], pubKeyBytes)
	pub = account.PubKeyEd25519(pubArray)
	addrBytes := pub.Address()

	if nonceS == "" {
		if nodeAddr == "" {
			err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or MINTX_NODE_ADDR) to fetch the nonce from a node")
			return
		}

		// fetch nonce from node
		client := cclient.NewClient(nodeAddr, "HTTP")
		ac, err2 := client.GetAccount(addrBytes)
		if err2 != nil {
			err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error())
			return
		}
		if ac == nil || ac.Account == nil {
			err = fmt.Errorf("unknown account %X", addrBytes)
			return
		}
		nonce = int64(ac.Account.Sequence) + 1
	} else {
		nonce, err = strconv.ParseInt(nonceS, 10, 64)
		if err != nil {
			err = fmt.Errorf("nonce is misformatted: %v", err)
			return
		}
	}

	return
}
Example #5
0
func before(c *cli.Context) error {
	nodeAddr := c.String("node-addr")
	client = cclient.NewClient(nodeAddr, REQUEST_TYPE)
	return nil
}
Example #6
0
	rpcAddr     = "pinkpenguin:46657"
	requestAddr = "http://" + rpcAddr + "/"

	PRIV_KEYS = []string{
		"9D25238C2E2221E8650ECF23A34458F5C3E5A90192EB5EDA6C4860FDCDB31508F6C79CF0CB9D66B677988BCB9B8EADD9A091CD465A60542A8AB85476256DBA92",
		"54A08F8CC74A6CB4BA8599FEEB6275E933429549362F040A31BB222DC28C97F2E15E88C226C5AEFF0597B4E71C9FEBF620538795C34CCCEB13D3CFECA8F6157B",
		"741DED293354D1BB27700559C0B6FDC5751582CBF8F9455DCEEA85A8AC78F8C5388180AC9AAF0C9A624DC0BC397A0FC0416E1713CD9181E41E8096DF5B6686FC",
		"866D9F061C2347AD40FF5B90C1EEAB49CEFDEC9329482C8C1B965A5C839A5D0DA0B0501D148232AD06BF9C57361FE35B490E2920A7622F2840F88D4097B7ECB3",
		"E7585E8E23CA0DC234BB77878E23F57CA99CB0E6F29DA7C2843A30F582565BCF6ED22473414B8DA547F5C781ADB12FB05BC6989A28BC0FADDA86D9831306F83C",
	}

	chainID = "tendermint_testnet_5e"

	keys = makeKeys()

	client = cclient.NewClient(requestAddr, "JSONRPC")
)

func makeKeys() (keys []*account.PrivAccount) {
	for _, k := range PRIV_KEYS {
		var privKeyBytes [64]byte
		keyBytes, _ := hex.DecodeString(k)
		copy(privKeyBytes[:], keyBytes)
		keys = append(keys, account.GenPrivAccountFromPrivKeyBytes(privKeyBytes[:]))
	}
	return
}

var txList = []string{"SendTx", "CallTx", "NameTx", "BondTx", "UnbondTx", "RebondTx"}

func main() {