示例#1
0
文件: peer.go 项目: Zoramite/ripple
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)
}
示例#2
0
文件: peer.go 项目: robcat/ripple
func (p *Peer) handleGetObjectByHashReply(reply *protocol.TMGetObjectByHash, l *ledger.Manager) {
	var nodes []*encoding.InnerNode
	for _, obj := range reply.GetObjects() {
		blob := append(obj.GetData(), obj.GetHash()...)
		node, err := encoding.ParseWire(blob)
		if err != nil {
			glog.Errorf("%s: %s Ledger: %d Blob: %X", p.String(), err.Error(), reply.GetSeq(), blob)
			return
		}
		if tx, ok := node.Value.(data.Transaction); ok {
			tx.SetLedgerSequence(reply.GetSeq())
			var hash data.Hash256
			copy(hash[:], obj.GetData()[len(obj.GetData())-32:])
			tx.SetHash(&hash)
			l.Incoming <- tx
		}
		if node.InnerNode != nil {
			nodes = append(nodes, node.InnerNode)
		}
	}
	if len(nodes) > 0 {
		p.synchronous <- protocol.NewGetObjects(reply.GetSeq(), nodes)
	}
}