Exemple #1
0
func (s *DiffSuite) TestDiff(c *C) {
	first, err := data.NewHash256("2C23D15B6B549123FB351E4B5CDE81C564318EB845449CD43C3EA7953C4DB452") // 38,129 Account Hash
	c.Assert(err, IsNil)
	second, err := data.NewHash256("AF47E9E91A41621B0F8AC5A119A5AD8B9E892147381BEAF6F2186127B89A44FF") // 38,128 Account Hash
	c.Assert(err, IsNil)
	diff, err := Diff(*first, *second, s.db)
	c.Assert(err, IsNil)
	c.Assert(diff.String(), DeepEquals, expectedDiff)
}
Exemple #2
0
func (s *DiffSuite) TestSummary(c *C) {
	ledger, err := data.NewHash256("E6DB7365949BF9814D76BCC730B01818EB9136A89DB224F3F9F5AAE4569D758E") // 38,129 Ledger Hash
	c.Assert(err, IsNil)
	state, err := NewLedgerStateFromDB(*ledger, s.db)
	c.Assert(err, IsNil)
	c.Assert(state.Fill(), IsNil)
	summary, err := state.Summary()
	c.Assert(err, IsNil)
	c.Assert(summary, DeepEquals, expectedSummary)
}
Exemple #3
0
func getInvoiceId(r *Request) string {
	s := fmt.Sprintf("%s%s%s%s%s%s%s%s%f%f%d", r.CTime.String(), r.UName, r.UWallet, r.UBankName, r.UBankId, r.UContact, r.Currency, r.Amount, r.Fees, r.Type)
	hash := sha256.Sum256([]byte(s))
	h, err := data.NewHash256(hash[:])
	if err != nil {
		glog.Error(err)
		return ""
	}
	return h.String()
}
Exemple #4
0
func TestMemStore(t *testing.T) {
	mem, err := NewMemoryDB([]string{"testdata/mem.gz"})
	checkErr(t, err)
	h1, err := data.NewHash256("CAD2E1FDC45A01998C75A2F50D2DFF3B77CE1451F3F58A328D1323917AC72FD7")
	checkErr(t, err)
	n1, err := mem.Get(*h1)
	checkErr(t, err)
	if _, ok := n1.(data.LedgerEntry); !ok {
		t.Fatalf("Expected LedgerEntry Got:%+v", n1)
	}
	if h1.Compare(*n1.GetHash()) != 0 {
		t.Fatalf("Expected Hash: %s Got:%s", h1, n1.GetHash())
	}
}
Exemple #5
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)
		}
	}
}