Пример #1
0
func HandleV2FactoidBalance(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	fadr := new(AddressRequest)
	err := MapToObject(params, fadr)
	if err != nil {
		return nil, NewInvalidParamsError()
	}

	var adr []byte

	if primitives.ValidateFUserStr(fadr.Address) {
		adr = primitives.ConvertUserStrToAddress(fadr.Address)
	} else {
		adr, err = hex.DecodeString(fadr.Address)
		if err == nil && len(adr) != constants.HASH_LENGTH {
			return nil, NewInvalidAddressError()
		}
		if err != nil {
			return nil, NewInvalidAddressError()
		}
	}

	if len(adr) != constants.HASH_LENGTH {
		return nil, NewInvalidAddressError()
	}

	resp := new(FactoidBalanceResponse)
	resp.Balance = state.GetFactoidState().GetFactoidBalance(factoid.NewAddress(adr).Fixed())
	return resp, nil
}
Пример #2
0
func (m *EOM) FollowerExecute(state interfaces.IState) error {

	state.GetFactoidState().EndOfPeriod(int(m.Minute))

	switch state.GetNetworkNumber() {
	case constants.NETWORK_MAIN: // Main Network
		panic("Not implemented yet")
	case constants.NETWORK_TEST: // Test Network
		panic("Not implemented yet")
	case constants.NETWORK_LOCAL: // Local Network

	default:
		panic(fmt.Sprintf("Not implemented yet: Network Number %d", state.GetNetworkNumber()))
	}

	// fmt.Println(state.GetServerState(), constants.SERVER_MODE)

	if m.Minute == 9 {
		state.ProcessEndOfBlock()
		if state.GetServerState() == constants.SERVER_MODE {
			state.LeaderInMsgQueue() <- m
		}
	}

	return nil
}
Пример #3
0
// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *FactoidTransaction) Validate(state interfaces.IState) int {
	err := state.GetFactoidState().Validate(1, m.Transaction)
	if err != nil {
		fmt.Println(err.Error())
		return -1
	}
	return 1
}
Пример #4
0
func (m *FactoidTransaction) Process(state interfaces.IState) {

	if m.processed {
		return
	}
	m.processed = true

	// We can only get a Factoid Transaction once.  Add it, and remove it from the lists.
	state.GetFactoidState().AddTransaction(1, m.Transaction)

}
Пример #5
0
// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *CommitEntryMsg) Validate(state interfaces.IState) int {
	if !m.validsig && !m.CommitEntry.IsValid() {
		return -1
	}
	m.validsig = true

	ebal := state.GetFactoidState().GetECBalance(*m.CommitEntry.ECPubKey)
	if int(m.CommitEntry.Credits) > int(ebal) {
		return 0
	}
	return 1
}
Пример #6
0
// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *CommitChainMsg) Validate(state interfaces.IState) int {
	if !m.CommitChain.IsValid() {
		return -1
	}
	ebal := state.GetFactoidState().GetECBalance(*m.CommitChain.ECPubKey)
	if int(m.CommitChain.Credits) > int(ebal) {
		return 0
	}

	return 1

}
Пример #7
0
func (m *FactoidTransaction) Process(dbheight uint32, state interfaces.IState) bool {
	if m.processed {
		return true
	}
	m.processed = true
	err := state.GetFactoidState().AddTransaction(1, m.Transaction)
	if err != nil {
		fmt.Println(err)
		return false
	}

	state.IncFactoidTrans()

	return true

}
Пример #8
0
// Execute the leader functions of the given message
func (m *FactoidTransaction) LeaderExecute(state interfaces.IState) error {
	if err := state.GetFactoidState().Validate(1, m.Transaction); err != nil {
		return err
	}
	b, err := m.Transaction.MarshalBinarySig()
	if err != nil {
		return err
	}
	msg, err := NewAck(state, primitives.Sha(b))
	if err != nil {
		return err
	}
	state.NetworkOutMsgQueue() <- msg
	state.FollowerInMsgQueue() <- m   // Send factoid trans to follower
	state.FollowerInMsgQueue() <- msg // Send the Ack to follower
	return nil
}
Пример #9
0
// Validate the message, given the state.  Three possible results:
//  < 0 -- Message is invalid.  Discard
//  0   -- Cannot tell if message is Valid
//  1   -- Message is valid
func (m *FactoidTransaction) Validate(state interfaces.IState) int {
	// Is the transaction well formed?
	err := m.Transaction.Validate(1)
	if err != nil {
		return -1 // No, object!
	}

	// Is the transaction properly signed?
	err = m.Transaction.ValidateSignatures()
	if err != nil {
		return -1 // No, object!
	}

	// Is the transaction valid at this point in time?
	err = state.GetFactoidState().Validate(1, m.Transaction)
	if err != nil {
		return 0 // Well, mumble.  Might be out of order.
	}
	return 1
}
Пример #10
0
func (m *CommitChainMsg) Process(state interfaces.IState) {
	ecblk := state.GetCurrentEntryCreditBlock()
	ecbody := ecblk.GetBody()
	ecbody.AddEntry(m.CommitChain)
	state.GetFactoidState().UpdateECTransaction(m.CommitChain)
}