func getAblock(hash string) *AblockHolder {
	mr, err := primitives.HexToHash(hash)
	if err != nil {
		return nil
	}

	holder := new(AblockHolder)

	dbase := StatePointer.GetAndLockDB()
	ablk, err := dbase.FetchABlock(mr)
	StatePointer.UnlockDB()

	if ablk == nil || err != nil {
		StatePointer.UnlockDB()
		return nil
	}
	bytes, err := ablk.JSONByte()
	if err != nil {
		return nil
	}
	err = json.Unmarshal(bytes, holder)
	if err != nil {
		return nil
	}

	holder.ABEntries = ablk.GetABEntries()

	for _, entry := range holder.ABEntries {
		disp := new(ABDisplayHolder)
		data, err := entry.MarshalBinary()
		if err != nil {
			return nil
		}
		switch entry.Type() {
		case constants.TYPE_MINUTE_NUM:
			r := new(adminBlock.EndOfMinuteEntry)
			err := r.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Minute Number"
			disp.OtherInfo = fmt.Sprintf("%x", r.MinuteNumber)
		case constants.TYPE_DB_SIGNATURE:
			r := new(adminBlock.DBSignatureEntry)
			err := r.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "DB Signature"
			disp.OtherInfo = "Server: " + r.IdentityAdminChainID.String()
		case constants.TYPE_REVEAL_MATRYOSHKA:
			r := new(adminBlock.RevealMatryoshkaHash)
			err := r.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Reveal Matryoshka Hash"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + r.IdentityChainID.String() + "</a><br />MHash: " + r.MHash.String()
		case constants.TYPE_ADD_MATRYOSHKA:
			m := new(adminBlock.AddReplaceMatryoshkaHash)
			err := m.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Matryoshka Hash"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + m.IdentityChainID.String() + "</a><br />MHash: " + m.MHash.String()
		case constants.TYPE_ADD_SERVER_COUNT:
			s := new(adminBlock.IncreaseServerCount)
			err := s.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Server Count"
			disp.OtherInfo = fmt.Sprintf("%x", s.Amount)
		case constants.TYPE_ADD_FED_SERVER:
			f := new(adminBlock.AddFederatedServer)
			err := f.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Federated Server"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + f.IdentityChainID.String() + "</a>"
		case constants.TYPE_ADD_AUDIT_SERVER:
			a := new(adminBlock.AddAuditServer)
			err := a.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Audit Server"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + a.IdentityChainID.String() + "</a>"
		case constants.TYPE_REMOVE_FED_SERVER:
			f := new(adminBlock.RemoveFederatedServer)
			err := f.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Remove Server"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + f.IdentityChainID.String() + "</a>"
		case constants.TYPE_ADD_FED_SERVER_KEY:
			f := new(adminBlock.AddFederatedServerSigningKey)
			err := f.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Server Key"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + f.IdentityChainID.String() + "</a><br />Key: " + f.PublicKey.String()
		case constants.TYPE_ADD_BTC_ANCHOR_KEY:
			b := new(adminBlock.AddFederatedServerBitcoinAnchorKey)
			err := b.UnmarshalBinary(data)
			if err != nil {
				continue
			}
			disp.Type = "Add Bitcoin Server Key"
			disp.OtherInfo = "Identity ChainID: <a href='' id='factom-search-link' type='chainhead'>" + b.IdentityChainID.String() + "</a>"
		}
		holder.ABDisplay = append(holder.ABDisplay, *disp)
	}

	return holder
}
Esempio n. 2
0
func (st *State) UpdateAuthorityFromABEntry(entry interfaces.IABEntry) error {
	var AuthorityIndex int
	data, err := entry.MarshalBinary()
	if err != nil {
		return err
	}
	switch entry.Type() {
	case constants.TYPE_REVEAL_MATRYOSHKA:
		r := new(adminBlock.RevealMatryoshkaHash)
		err := r.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		// Does nothing for authority right now
	case constants.TYPE_ADD_MATRYOSHKA:
		m := new(adminBlock.AddReplaceMatryoshkaHash)
		err := m.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		AuthorityIndex = st.AddAuthorityFromChainID(m.IdentityChainID)
		st.Authorities[AuthorityIndex].MatryoshkaHash = m.MHash
	case constants.TYPE_ADD_SERVER_COUNT:
		s := new(adminBlock.IncreaseServerCount)
		err := s.UnmarshalBinary(data)
		if err != nil {
			return err
		}

		st.AuthorityServerCount = st.AuthorityServerCount + int(s.Amount)
	case constants.TYPE_ADD_FED_SERVER:
		f := new(adminBlock.AddFederatedServer)
		err := f.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		err = st.AddIdentityFromChainID(f.IdentityChainID)
		if err != nil {
			//fmt.Println("Error when Making Identity,", err)
		}
		AuthorityIndex = st.AddAuthorityFromChainID(f.IdentityChainID)
		st.Authorities[AuthorityIndex].Status = constants.IDENTITY_FEDERATED_SERVER
		// check Identity status
		UpdateIdentityStatus(f.IdentityChainID, constants.IDENTITY_FEDERATED_SERVER, st)
	case constants.TYPE_ADD_AUDIT_SERVER:
		a := new(adminBlock.AddAuditServer)
		err := a.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		err = st.AddIdentityFromChainID(a.IdentityChainID)
		if err != nil {
			//fmt.Println("Error when Making Identity,", err)
		}
		AuthorityIndex = st.AddAuthorityFromChainID(a.IdentityChainID)
		st.Authorities[AuthorityIndex].Status = constants.IDENTITY_AUDIT_SERVER
		// check Identity status
		UpdateIdentityStatus(a.IdentityChainID, constants.IDENTITY_AUDIT_SERVER, st)
	case constants.TYPE_REMOVE_FED_SERVER:
		f := new(adminBlock.RemoveFederatedServer)
		err := f.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		AuthorityIndex = st.isAuthorityChain(f.IdentityChainID)
		if AuthorityIndex == -1 {
			log.Println(f.IdentityChainID.String() + " Cannot be removed.  Not in Authorities List.")
		} else {
			st.RemoveAuthority(f.IdentityChainID)
			IdentityIndex := st.isIdentityChain(f.IdentityChainID)
			if IdentityIndex != -1 && IdentityIndex < len(st.Identities) {
				if st.Identities[IdentityIndex].IdentityChainID.IsSameAs(st.IdentityChainID) {
					st.Identities[IdentityIndex].Status = constants.IDENTITY_SELF
				} else {
					st.removeIdentity(IdentityIndex)
				}
			}
		}
	case constants.TYPE_ADD_FED_SERVER_KEY:
		f := new(adminBlock.AddFederatedServerSigningKey)
		err := f.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		keyBytes, err := f.PublicKey.MarshalBinary()
		if err != nil {
			return err
		}
		key := new(primitives.Hash)
		err = key.SetBytes(keyBytes)
		if err != nil {
			return err
		}
		addServerSigningKey(f.IdentityChainID, key, f.DBHeight, st)
	case constants.TYPE_ADD_BTC_ANCHOR_KEY:
		b := new(adminBlock.AddFederatedServerBitcoinAnchorKey)
		err := b.UnmarshalBinary(data)
		if err != nil {
			return err
		}
		pubKey, err := b.ECDSAPublicKey.MarshalBinary()
		if err != nil {
			return err
		}
		registerAuthAnchor(b.IdentityChainID, pubKey, b.KeyType, b.KeyPriority, st, "BTC")
	}
	return nil
}