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 }
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 }