Exemplo n.º 1
0
func HandleV2RevealEntry(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	e := new(EntryRequest)
	err := MapToObject(params, e)
	if err != nil {
		return nil, NewInvalidParamsError()
	}

	entry := entryBlock.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		return nil, NewInvalidEntryError()
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			return nil, NewInvalidEntryError()
		}
	}

	msg := new(messages.RevealEntryMsg)
	msg.Entry = entry
	msg.Timestamp = state.GetTimestamp()
	state.APIQueue() <- msg

	resp := new(RevealEntryResponse)
	resp.Message = "Entry Reveal Success"
	resp.EntryHash = entry.GetHash().String()

	return resp, nil
}
Exemplo n.º 2
0
func HandleRevealEntry(ctx *web.Context) {
	type revealentry struct {
		Entry string
	}

	e := new(revealentry)
	if p, err := ioutil.ReadAll(ctx.Request.Body); err != nil {
		returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
		return
	} else {
		if err := json.Unmarshal(p, e); err != nil {
			returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
			return
		}
	}

	entry := entryBlock.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
		return
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			returnMsg(ctx, "Error Reveal Entry: "+err.Error(), false)
			return
		}
	}

	state := ctx.Server.Env["state"].(interfaces.IState)

	msg := new(messages.RevealEntryMsg)
	msg.Entry = entry
	msg.Timestamp = state.GetTimestamp()
	state.InMsgQueue() <- msg

	returnMsg(ctx, "Entry Reveal Success", true)
}
Exemplo n.º 3
0
func DeepStateDisplayCopy(s *State) (*DisplayState, error) {
	ds := NewDisplayState()

	ds.NodeName = s.GetFactomNodeName()
	ds.ControlPanelPort = s.ControlPanelPort
	ds.ControlPanelSetting = s.ControlPanelSetting

	// DB Info
	ds.CurrentNodeHeight = s.GetHighestCompletedBlock()
	ds.CurrentLeaderHeight = s.GetLeaderHeight()
	ds.CurrentEBDBHeight = s.EntryBlockDBHeightProcessing
	ds.ProcessListHeight = uint32(int(s.ProcessLists.DBHeightBase) + len(s.ProcessLists.Lists) - 1)
	dir := s.GetDirectoryBlockByHeight(s.GetLeaderHeight())
	if dir == nil {
		dir = s.GetDirectoryBlockByHeight(s.GetLeaderHeight() - 1)
	}
	if dir != nil {
		data, err := dir.MarshalBinary()
		if err != nil || dir == nil {
		} else {
			newDBlock, err := directoryBlock.UnmarshalDBlock(data)
			if err != nil {
				ds.LastDirectoryBlock = nil
			} else {
				ds.LastDirectoryBlock = newDBlock
			}
		}
	}

	// Identities
	ds.IdentityChainID = s.GetIdentityChainID().Copy()
	for _, id := range s.Identities {
		ds.Identities = append(ds.Identities, id)
	}
	for _, auth := range s.Authorities {
		ds.Authorities = append(ds.Authorities, auth)
	}
	if pubkey, err := s.GetServerPublicKey().Copy(); err != nil {

	} else {
		ds.PublicKey = pubkey
	}

	vms := s.LeaderPL.VMs
	for _, v := range vms {
		list := v.List
		for _, msg := range list {
			if msg == nil {
				continue
			}
			switch msg.Type() {
			case constants.REVEAL_ENTRY_MSG:
				data, err := msg.MarshalBinary()
				if err != nil {
					continue
				}
				rev := new(messages.RevealEntryMsg)
				err = rev.UnmarshalBinary(data)
				if rev.Entry == nil || err != nil {
					continue
				}

				var entry EntryTransaction
				entry.ChainID = "Processing..."
				entry.EntryHash = rev.Entry.GetHash().String()

				ds.PLEntry = append(ds.PLEntry, entry)
			case constants.FACTOID_TRANSACTION_MSG:
				data, err := msg.MarshalBinary()
				if err != nil {
					continue
				}
				transMsg := new(messages.FactoidTransaction)
				err = transMsg.UnmarshalBinary(data)
				if transMsg.Transaction == nil || err != nil {
					continue
				}
				trans := transMsg.Transaction
				input, err := trans.TotalInputs()
				if err != nil {
					continue
				}
				totalInputs := len(trans.GetInputs())
				totalOutputs := len(trans.GetECOutputs())
				totalOutputs = totalOutputs + len(trans.GetOutputs())
				inputStr := fmt.Sprintf("%f", float64(input)/1e8)

				ds.PLFactoid = append(ds.PLFactoid, struct {
					TxID         string
					Hash         string
					TotalInput   string
					Status       string
					TotalInputs  int
					TotalOutputs int
				}{trans.GetSigHash().String(), trans.GetHash().String(), inputStr, "Process List", totalInputs, totalOutputs})
			}
		}
	}

	prt := "===SummaryStart===\n"
	s.Status = 1
	prt = prt + fmt.Sprintf("%s \n", s.ShortString())
	fnodes := make([]*State, 0)
	fnodes = append(fnodes, s)
	prt = prt + messageLists(fnodes)
	prt = prt + "===SummaryEnd===\n"

	ds.RawSummary = prt

	b := s.GetHighestCompletedBlock()
	pl := s.ProcessLists.Get(b + 1)
	if pl == nil {
		pl = s.ProcessLists.Get(b)
	}
	if pl != nil && pl.FedServers != nil {
		ds.PrintMap = pl.PrintMap()
		ds.ProcessList = pl.String()
	} else {
		ds.PrintMap = ""
		ds.ProcessList = ""
	}

	return ds, nil
}