Esempio n. 1
0
func HandleV2FactoidSubmit(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	t := new(TransactionRequest)
	err := MapToObject(params, t)
	if err != nil {
		return nil, NewInvalidParamsError()
	}

	msg := new(messages.FactoidTransaction)

	p, err := hex.DecodeString(t.Transaction)
	if err != nil {
		return nil, NewUnableToDecodeTransactionError()
	}

	_, err = msg.UnmarshalTransData(p)
	if err != nil {
		return nil, NewUnableToDecodeTransactionError()
	}

	state.IncFCTSubmits()

	state.APIQueue() <- msg

	resp := new(FactoidSubmitResponse)
	resp.Message = "Successfully submitted the transaction"
	resp.TxID = msg.Transaction.GetSigHash().String()

	return resp, nil
}
Esempio n. 2
0
func HandleFactoidSubmit(ctx *web.Context) {
	state := ctx.Server.Env["state"].(interfaces.IState)

	type x struct{ Transaction string }
	t := new(x)

	var p []byte
	var err error
	if p, err = ioutil.ReadAll(ctx.Request.Body); err != nil {
		wsLog.Error(err)
		returnMsg(ctx, "Unable to read the request", false)
		return
	} else {
		if err := json.Unmarshal(p, t); err != nil {
			returnMsg(ctx, "Unable to Unmarshal the request", false)
			return
		}
	}

	msg := new(messages.FactoidTransaction)

	if p, err = hex.DecodeString(t.Transaction); err != nil {
		returnMsg(ctx, "Unable to decode the transaction", false)
		return
	}

	_, err = msg.UnmarshalTransData(p)

	if err != nil {
		returnMsg(ctx, err.Error(), false)
		return
	}

	err = state.GetFactoidState().Validate(1, msg.Transaction)

	if err != nil {
		returnMsg(ctx, err.Error(), false)
		return
	}

	state.InMsgQueue() <- msg

	returnMsg(ctx, "Successfully submitted the transaction", true)

}
Esempio 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
}