本文整理匯總了Golang中github.com/FactomProject/factomd/common/primitives.Sha函數的典型用法代碼示例。如果您正苦於以下問題:Golang Sha函數的具體用法?Golang Sha怎麽用?Golang Sha使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Sha函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetLedgerMR
// Returns the LedgerMR for this block.
func (b *FBlock) GetLedgerMR() interfaces.IHash {
b.EndOfPeriod(0) // Clean up end of minute markers, if needed.
hashes := make([]interfaces.IHash, 0, len(b.Transactions))
marker := 0
for i, trans := range b.Transactions {
for marker < len(b.endOfPeriod) && i != 0 && i == b.endOfPeriod[marker] {
marker++
hashes = append(hashes, primitives.Sha(constants.ZERO))
}
data, err := trans.MarshalBinarySig()
hash := primitives.Sha(data)
if err != nil {
panic("Failed to get LedgerMR: " + err.Error())
}
hashes = append(hashes, hash)
}
// Add any lagging markers
for marker < len(b.endOfPeriod) {
marker++
hashes = append(hashes, primitives.Sha(constants.ZERO))
}
lmr := primitives.ComputeMerkleRoot(hashes)
return lmr
}
示例2: newChangeServerKey
func newChangeServerKey() *ChangeServerKeyMsg {
addserv := new(ChangeServerKeyMsg)
addserv.Timestamp = primitives.NewTimestampNow()
addserv.IdentityChainID = primitives.Sha([]byte("FNode0"))
addserv.AdminBlockChange = 0
addserv.KeyPriority = 0
addserv.KeyType = 0
addserv.Key = primitives.Sha([]byte("A_Key"))
return addserv
}
示例3: KeyMR
// KeyMR returns the hash of the hash of the Entry Block Header concatinated
// with the Merkle Root of the Entry Block Body. The Body Merkle Root is
// calculated by the func (e *EBlockBody) MR() which is called by the func
// (e *EBlock) BuildHeader().
func (e *EBlock) KeyMR() (interfaces.IHash, error) {
// Sha(Sha(header) + BodyMR)
e.BuildHeader()
header, err := e.Header.MarshalBinary()
if err != nil {
return nil, err
}
h := primitives.Sha(header)
return primitives.Sha(append(h.Bytes(), e.Header.GetBodyMR().Bytes()...)), nil
}
示例4: GetLedgerKeyMR
func (b *FBlock) GetLedgerKeyMR() interfaces.IHash {
ledgerMR := b.GetLedgerMR()
data, err := b.MarshalHeader()
if err != nil {
panic("Failed to create FullHash: " + err.Error())
}
headerHash := primitives.Sha(data)
cat := append(ledgerMR.Bytes(), headerHash.Bytes()...)
lkmr := primitives.Sha(cat)
return lkmr
}
示例5: GetKeyMR
// Calculates the Key Merkle Root for this block and returns it.
func (b *FBlock) GetKeyMR() interfaces.IHash {
bodyMR := b.GetBodyMR()
data, err := b.MarshalHeader()
if err != nil {
panic("Failed to create KeyMR: " + err.Error())
}
headerHash := primitives.Sha(data)
cat := append(headerHash.Bytes(), bodyMR.Bytes()...)
kmr := primitives.Sha(cat)
return kmr
}
示例6: BuildBodyMR
func (b *DirectoryBlock) BuildBodyMR() (mr interfaces.IHash, err error) {
hashes := make([]interfaces.IHash, len(b.GetDBEntries()))
for i, entry := range b.GetDBEntries() {
data, _ := entry.MarshalBinary()
hashes[i] = primitives.Sha(data)
}
if len(hashes) == 0 {
hashes = append(hashes, primitives.Sha(nil))
}
merkle := primitives.BuildMerkleTreeStore(hashes)
return merkle[len(merkle)-1], nil
}
示例7: Hash
func (e *CommitChain) Hash() interfaces.IHash {
bin, err := e.MarshalBinary()
if err != nil {
panic(err)
}
return primitives.Sha(bin)
}
示例8: GenerateGenesisBlocks
func GenerateGenesisBlocks(networkID uint32) (interfaces.IDirectoryBlock, interfaces.IAdminBlock, interfaces.IFBlock, interfaces.IEntryCreditBlock) {
dblk := directoryBlock.NewDirectoryBlock(nil)
ablk := adminBlock.NewAdminBlock(nil)
fblk := factoid.GetGenesisFBlock(networkID)
ecblk := entryCreditBlock.NewECBlock()
if networkID != constants.MAIN_NETWORK_ID {
if networkID == constants.TEST_NETWORK_ID {
ablk.AddFedServer(primitives.NewZeroHash())
} else {
ablk.AddFedServer(primitives.Sha([]byte("FNode0")))
}
} else {
ecblk.GetBody().AddEntry(entryCreditBlock.NewServerIndexNumber())
for i := 1; i < 11; i++ {
minute := entryCreditBlock.NewMinuteNumber(uint8(i))
ecblk.GetBody().AddEntry(minute)
}
}
dblk.SetABlockHash(ablk)
dblk.SetECBlockHash(ecblk)
dblk.SetFBlockHash(fblk)
dblk.GetHeader().SetNetworkID(networkID)
dblk.GetHeader().SetTimestamp(primitives.NewTimestampFromMinutes(24018960))
return dblk, ablk, fblk, ecblk
}
示例9: CreateTestDirectoryBlockHeader
func CreateTestDirectoryBlockHeader(prevBlock *directoryBlock.DirectoryBlock) *directoryBlock.DBlockHeader {
header := new(directoryBlock.DBlockHeader)
header.SetBodyMR(primitives.Sha(primitives.NewZeroHash().Bytes()))
header.SetBlockCount(0)
header.SetNetworkID(constants.MAIN_NETWORK_ID)
if prevBlock == nil {
header.SetDBHeight(0)
header.SetPrevFullHash(primitives.NewZeroHash())
header.SetPrevKeyMR(primitives.NewZeroHash())
header.SetTimestamp(primitives.NewTimestampFromMinutes(1234))
} else {
header.SetDBHeight(prevBlock.Header.GetDBHeight() + 1)
header.SetPrevFullHash(prevBlock.GetHash())
keyMR, err := prevBlock.BuildKeyMerkleRoot()
if err != nil {
panic(err)
}
header.SetPrevKeyMR(keyMR)
header.SetTimestamp(primitives.NewTimestampFromMinutes(prevBlock.Header.GetTimestamp().GetTimeMinutesUInt32() + 1))
}
header.SetVersion(1)
return header
}
示例10: GetSigHash
func (t Transaction) GetSigHash() interfaces.IHash {
m, err := t.MarshalBinarySig()
if err != nil {
return nil
}
return primitives.Sha(m)
}
示例11: GetSigHash
func (c *CommitChain) GetSigHash() interfaces.IHash {
if c.SigHash == nil {
data := c.CommitMsg()
c.SigHash = primitives.Sha(data)
}
return c.SigHash
}
示例12: Test_Factoid_Addresses
func Test_Factoid_Addresses(test *testing.T) {
addr := NewAddress(primitives.Sha([]byte("A fake address")).Bytes())
uaddr := primitives.ConvertFctAddressToUserStr(addr)
if !primitives.ValidateFUserStr(uaddr) {
test.Fail()
}
addrBack := primitives.ConvertUserStrToAddress(uaddr)
if bytes.Compare(addrBack, addr.Bytes()) != 0 {
test.Fail()
}
buaddr := []byte(uaddr)
for i, v := range buaddr {
for j := uint(0); j < 8; j++ {
if !primitives.ValidateFUserStr(string(buaddr)) {
test.Fail()
}
buaddr[i] = v ^ (01 << j)
if primitives.ValidateFUserStr(string(buaddr)) {
test.Fail()
}
buaddr[i] = v
}
}
}
示例13: Hash
func (e *RevealMatryoshkaHash) Hash() interfaces.IHash {
bin, err := e.MarshalBinary()
if err != nil {
panic(err)
}
return primitives.Sha(bin)
}
示例14: GetHash
func (fc *FaultCore) GetHash() interfaces.IHash {
data, err := fc.MarshalCore()
if err != nil {
return nil
}
return primitives.Sha(data)
}
示例15: GetCoreHash
func (m *ServerFault) GetCoreHash() interfaces.IHash {
data, err := m.MarshalForSignature()
if err != nil {
return nil
}
return primitives.Sha(data)
}