func TestDiff(t *testing.T) { mem, err := storage.NewMemoryDB("testdata/38129-32570.gz") checkErr(t, err) first, err := data.NewHash256("2C23D15B6B549123FB351E4B5CDE81C564318EB845449CD43C3EA7953C4DB452") checkErr(t, err) second, err := data.NewHash256("AF47E9E91A41621B0F8AC5A119A5AD8B9E892147381BEAF6F2186127B89A44FF") checkErr(t, err) diff, err := Diff2(first, second, mem) checkErr(t, err) var buf bytes.Buffer checkErr(t, diff.Dump(uint32(0), &buf)) if buf.String() != expectedDiff { t.Errorf("Wrong diff!\n%s\nExpected:\n%s\n", buf.String(), expectedDiff) } }
func TestMemStore(t *testing.T) { mem, err := NewMemoryDB("testdata/mem.gz") checkErr(t, err) h1, err := data.NewHash256("CAD2E1FDC45A01998C75A2F50D2DFF3B77CE1451F3F58A328D1323917AC72FD7") checkErr(t, err) n1, err := mem.Get(h1) checkErr(t, err) if n1.InnerNode != nil { t.Log("Expected Inner Node") } }
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) } } }
func (p *Peer) handleGetObjectByHashReply(reply *protocol.TMGetObjectByHash) { var nodes []data.Hashable typ := data.NT_ACCOUNT_NODE if reply.GetType() == protocol.TMGetObjectByHash_otTRANSACTION_NODE { typ = data.NT_TRANSACTION_NODE } for _, obj := range reply.GetObjects() { blob := append(obj.GetData(), obj.GetHash()...) nodeid, err := data.NewHash256(obj.GetIndex()) if err != nil { glog.Errorf("%s: %s Ledger: %d Blob: %X", p.String(), err.Error(), reply.GetSeq(), blob) return } node, err := data.ReadWire(bytes.NewReader(blob), typ, reply.GetSeq(), *nodeid) if err != nil { glog.Errorf("%s: %s Ledger: %d Blob: %X", p.String(), err.Error(), reply.GetSeq(), blob) return } glog.Infoln(node) nodes = append(nodes, node) } p.sync.Submit(nodes) }
func (p *Peer) handleLedgerData(ledgerData *protocol.TMLedgerData) { if ledgerData.GetType() != protocol.TMLedgerInfoType_liBASE { glog.Infof("%s: Ignoring: %s", ledgerData.Log()) return } nodeid, err := data.NewHash256(ledgerData.Nodes[0].Nodeid) if err != nil { glog.Errorf("%s: %s", p.String(), err.Error()) return } ledger, err := data.ReadLedger(bytes.NewReader(ledgerData.Nodes[0].Nodedata), *nodeid) if err != nil { glog.Errorf("%s: %s", p.String(), err.Error()) return } glog.Infoln(ledger) p.sync.Submit([]data.Hashable{ledger}) // transactions, err := encoding.ParseUnknownInnerNode(ledgerData.Nodes[2].Nodedata) // if err != nil { // glog.Errorf("%s: %s", p.String(), err.Error()) // return // } // p.synchronous <- protocol.NewGetObjects(ledger.LedgerSequence, []*encoding.InnerNode{transactions}) }