Exemplo n.º 1
0
func submitTx(tx data.Transaction) {
	r, err := websockets.NewRemote("wss://s-east.ripple.com:443")
	checkErr(err)
	go r.Run()
	result, err := r.Submit(tx)
	checkErr(err)
	fmt.Printf("%s: %s\n", result.EngineResult, result.EngineResultMessage)
	os.Exit(0)
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) == 1 {
		showUsage()
	}
	flags.Parse(os.Args[2:])
	matches := argumentRegex.FindStringSubmatch(os.Args[1])
	r, err := websockets.NewRemote(*host)
	checkErr(err)
	glog.Infoln("Connected to: ", *host)
	go r.Run()
	switch {
	case len(matches) == 0:
		showUsage()
	case len(matches[1]) > 0:
		hash, err := data.NewHash256(matches[1])
		checkErr(err)
		fmt.Println("Getting transaction: ", hash.String())
		result, err := r.Tx(*hash)
		checkErr(err)
		explain(&result.TransactionWithMetaData, terminal.Default)
	case len(matches[2]) > 0:
		seq, err := strconv.ParseUint(matches[2], 10, 32)
		checkErr(err)
		ledger, err := r.Ledger(seq, true)
		checkErr(err)
		fmt.Println("Getting transactions for: ", seq)
		for _, txm := range ledger.Ledger.Transactions {
			explain(txm, terminal.Default)
		}
	case len(matches[3]) > 0:
		account, err := data.NewAccountFromAddress(matches[3])
		checkErr(err)
		fmt.Println("Getting transactions for: ", account.String())
		for txm := range r.AccountTx(*account, *pageSize) {
			explain(txm, terminal.ShowLedgerSequence)
		}
	case len(matches[4]) > 0:
		r := bufio.NewReader(os.Stdin)
		for line, err := r.ReadString('\n'); err == nil; line, err = r.ReadString('\n') {
			// TODO: Accept nodeid:nodedata format
			b, err := hex.DecodeString(line[:len(line)-1])
			checkErr(err)
			var nodeid data.Hash256
			v, err := data.ReadPrefix(bytes.NewReader(b), nodeid)
			checkErr(err)
			terminal.Println(v, terminal.Default)
		}
	}
}
Exemplo n.º 3
0
func main() {
	flag.Parse()
	r, err := websockets.NewRemote(*host)
	checkErr(err, true)
	go r.Run()

	// Subscribe to all streams
	confirmation, err := r.Subscribe(true, true, true)
	checkErr(err, true)
	terminal.Println(fmt.Sprint("Subscribed at: ", confirmation.LedgerSequence), terminal.Default)

	// Consume messages as they arrive
	for {
		msg, ok := <-r.Incoming
		if !ok {
			return
		}

		switch msg := msg.(type) {
		case *websockets.LedgerStreamMsg:
			terminal.Println(msg, terminal.Default)
		case *websockets.TransactionStreamMsg:
			terminal.Println(&msg.Transaction, terminal.Indent)
			for _, path := range msg.Transaction.PathSet() {
				terminal.Println(path, terminal.DoubleIndent)
			}
			trades, err := msg.Transaction.Trades()
			checkErr(err, false)
			for _, trade := range trades {
				terminal.Println(trade, terminal.DoubleIndent)
			}
			balances, err := msg.Transaction.Balances()
			checkErr(err, false)
			for _, balance := range balances {
				terminal.Println(balance, terminal.DoubleIndent)
			}
		case *websockets.ServerStreamMsg:
			terminal.Println(msg, terminal.Default)
		}
	}
}