Beispiel #1
0
func checkErr(err error, quit bool) {
	if err != nil {
		terminal.Println(err.Error(), terminal.Default)
		if quit {
			os.Exit(1)
		}
	}
}
Beispiel #2
0
func explain(txm *data.TransactionWithMetaData, flag terminal.Flag) {
	if !*transactions {
		terminal.Println(txm, flag)
	}
	if !*paths {
		for _, path := range txm.PathSet() {
			terminal.Println(path, flag|terminal.Indent)
		}
	}
	if !*trades {
		trades, err := txm.Trades()
		checkErr(err)
		for _, trade := range trades {
			terminal.Println(trade, flag|terminal.Indent)
		}
	}
	if !*balances {
		balances, err := txm.Balances()
		checkErr(err)
		for _, balance := range balances {
			terminal.Println(balance, flag|terminal.Indent)
		}
	}
}
Beispiel #3
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)
	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)
		}
	}
}
Beispiel #4
0
func main() {
	if len(os.Args) == 1 {
		showUsage()
	}
	flag.CommandLine.Parse(os.Args[2:])

	remote, err := websockets.NewRemote(*host)
	checkErr(err)
	account, err := data.NewAccountFromAddress(os.Args[1])
	checkErr(err)
	result, err := remote.AccountLines(*account, "closed")
	checkErr(err)
	// fmt.Println(*result.LedgerSequence) //TODO: wait for nikb fix
	for _, line := range result.Lines {
		terminal.Println(line, terminal.Default)
	}
}
Beispiel #5
0
func (m *Manager) Start() {
	m.started = time.Now()
	tick := time.NewTicker(time.Minute)
	var held CanonicalTxSet
	for {
		select {
		case <-tick.C:
			glog.Infoln("Manager:", m.String())
		case current := <-m.current:
			if current > m.ledgers.Max() {
				m.ledgers.Extend(current)
				glog.Infoln(current, m.ledgers.Max())
			}
		case in := <-m.incoming:
			for _, item := range in {
				terminal.Println(item, terminal.ShowTransactionId)
				switch v := item.(type) {
				case *data.Validation:
					continue
				case *data.Proposal:
					continue
				case *data.Ledger:
					m.stats["ledgers"]++
					wait := m.ledgers.Set(v.LedgerSequence)
					glog.V(2).Infof("Manager: Received: %d %0.04f/secs ", v.LedgerSequence, wait.Seconds())
					if err := m.db.Insert(v); err != nil {
						glog.Errorln("Manager: Ledger Insert:", err.Error())
					}
				case *data.TransactionWithMetaData:
					m.stats["transactions"]++
					if err := m.db.Insert(v); err != nil {
						glog.Errorln("Manager: Transaction Insert:", err.Error())
					}
				case data.Transaction:
					held.Add(v)
				}
			}
		case missing := <-m.missing:
			continue
			work := <-missing
			m.ledgers.Extend(work.End)
			work.MissingLedgers = m.ledgers.TakeMiddle(work.LedgerRange)
			missing <- work
		}
	}
}
Beispiel #6
0
func main() {
	if len(os.Args) == 1 {
		showUsage()
	}
	flag.CommandLine.Parse(os.Args[2:])

	remote, err := websockets.NewRemote(*host)
	checkErr(err)
	account, err := data.NewAccountFromAddress(os.Args[1])
	checkErr(err)
	result, err := remote.AccountOffers(*account, "closed")
	checkErr(err)
	fmt.Println(*result.LedgerSequence)
	for _, offer := range result.Offers {
		terminal.Println(offer, terminal.Default)
	}
}
Beispiel #7
0
func main() {
	if len(os.Args) != 3 {
		showUsage()
	}
	flag.CommandLine.Parse(os.Args[3:])

	remote, err := websockets.NewRemote(*host)
	checkErr(err)
	gets, err := data.NewAsset(os.Args[1])
	checkErr(err)
	pays, err := data.NewAsset(os.Args[2])
	checkErr(err)
	var zeroAccount data.Account
	result, err := remote.BookOffers(zeroAccount, "closed", *pays, *gets)
	checkErr(err)
	// fmt.Println(*result.LedgerSequence) //TODO: wait for nikb fix
	for _, offer := range result.Offers {
		terminal.Println(offer, terminal.Default)
	}
}
Beispiel #8
0
func main() {
	flag.Parse()
	r, err := websockets.NewRemote(*host)
	checkErr(err, true)

	// Subscribe to all streams
	confirmation, err := r.Subscribe(true, false, 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)
		}
	}
}
Beispiel #9
0
func checkErr(err error) {
	if err != nil {
		terminal.Println(err.Error(), terminal.Default)
		os.Exit(1)
	}
}