本文整理匯總了Golang中github.com/FactomProject/factomd/common/primitives.HexToHash函數的典型用法代碼示例。如果您正苦於以下問題:Golang HexToHash函數的具體用法?Golang HexToHash怎麽用?Golang HexToHash使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了HexToHash函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setupFirstAuthority
func setupFirstAuthority(s *state.State) {
var id state.Identity
if networkIdentity := s.GetNetworkBootStrapIdentity(); networkIdentity != nil {
id.IdentityChainID = networkIdentity
} else {
id.IdentityChainID = primitives.NewZeroHash()
}
id.ManagementChainID, _ = primitives.HexToHash("88888800000000000000000000000000")
if pub := s.GetNetworkBootStrapKey(); pub != nil {
id.SigningKey = pub
} else {
id.SigningKey = primitives.NewZeroHash()
}
id.MatryoshkaHash = primitives.NewZeroHash()
id.ManagementCreated = 0
id.ManagementRegistered = 0
id.IdentityCreated = 0
id.IdentityRegistered = 0
id.Key1 = primitives.NewZeroHash()
id.Key2 = primitives.NewZeroHash()
id.Key3 = primitives.NewZeroHash()
id.Key4 = primitives.NewZeroHash()
id.Status = 1
s.Identities = append(s.Identities, &id)
var auth state.Authority
auth.Status = 1
auth.SigningKey = primitives.PubKeyFromString(id.SigningKey.String())
auth.MatryoshkaHash = primitives.NewZeroHash()
auth.AuthorityChainID = id.IdentityChainID
auth.ManagementChainID, _ = primitives.HexToHash("88888800000000000000000000000000")
s.Authorities = append(s.Authorities, &auth)
}
示例2: TestOutECAddress
func TestOutECAddress(t *testing.T) {
h, err := primitives.HexToHash("ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973")
if err != nil {
t.Error(err)
}
add := h.(interfaces.IAddress)
outECAdd := NewOutECAddress(add, 12345678)
str := outECAdd.String()
t.Logf("outECAdd str - %v", str)
if strings.Contains(str, "ecoutput") == false {
t.Error("'ecoutput' not found")
}
if strings.Contains(str, "0.12345678") == false {
t.Error("'0.12345678' not found")
}
if strings.Contains(str, "EC3ZMxDt8xUBKBmrmzLwSpnMHkdptLS8gTSf8NQhVf7vpAWqNE2p") == false {
t.Error("'EC3ZMxDt8xUBKBmrmzLwSpnMHkdptLS8gTSf8NQhVf7vpAWqNE2p' not found")
}
if strings.Contains(str, "0000000000bc614e") == false {
t.Error("'0000000000bc614e' not found")
}
if strings.Contains(str, "ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973") == false {
t.Error("'ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973' not found")
}
}
示例3: getECblock
func getECblock(hash string) *ECBlockHolder {
mr, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
dbase := StatePointer.GetAndLockDB()
ecblk, err := dbase.FetchECBlock(mr)
StatePointer.UnlockDB()
if ecblk == nil || err != nil {
return nil
}
if ecblk.GetHeader() == nil {
return nil
}
holder := new(ECBlockHolder)
holder.ECBlock = ecblk
length := 0
zero := primitives.NewZeroHash()
for _, e := range ecblk.GetEntryHashes() {
if e != nil && !e.IsSameAs(zero) {
length++
}
}
holder.Length = length
return holder
}
示例4: TestTransAddressMarshalUnmarshal
func TestTransAddressMarshalUnmarshal(t *testing.T) {
ta := new(TransAddress)
ta.SetAmount(12345678)
h, err := primitives.HexToHash("ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973")
if err != nil {
t.Error(err)
}
add := h.(interfaces.IAddress)
ta.SetAddress(add)
hex, err := ta.MarshalBinary()
if err != nil {
t.Error(err)
}
ta2 := new(TransAddress)
err = ta2.UnmarshalBinary(hex)
if err != nil {
t.Error(err)
}
json1, err := ta.JSONString()
if err != nil {
t.Error(err)
}
json2, err := ta2.JSONString()
if err != nil {
t.Error(err)
}
if json1 != json2 {
t.Error("JSONs are not identical")
}
}
示例5: getFactTransaction
func getFactTransaction(hash string) interfaces.ITransaction {
mr, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
dbase := StatePointer.GetAndLockDB()
trans, err := dbase.FetchFactoidTransaction(mr)
StatePointer.UnlockDB()
if trans == nil || err != nil {
return nil
}
if trans.GetInputs() == nil {
return nil
}
status := getFactoidAck(hash)
if status == nil {
return struct {
interfaces.ITransaction
wsapi.FactoidTxStatus
}{trans, *status}
}
return struct {
interfaces.ITransaction
wsapi.FactoidTxStatus
}{trans, *status}
}
示例6: getFblock
func getFblock(hash string) *FBlockHolder {
mr, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
dbase := StatePointer.GetAndLockDB()
fblk, err := dbase.FetchFBlock(mr)
StatePointer.UnlockDB()
if fblk == nil || err != nil {
return nil
}
bytes, err := fblk.MarshalBinary()
if err != nil {
return nil
}
holder := new(FBlockHolder)
err = holder.UnmarshalBinary(bytes)
if err != nil {
return nil
}
holder.Length = len(holder.Transactions)
return holder
}
示例7: TestInAddress
func TestInAddress(t *testing.T) {
h, err := primitives.HexToHash("ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973")
if err != nil {
t.Error(err)
}
add := h.(interfaces.IAddress)
inAdd := NewInAddress(add, 12345678)
str := inAdd.String()
t.Logf("InAdd str - %v", str)
if strings.Contains(str, "input") == false {
t.Error("'input' not found")
}
if strings.Contains(str, "0.12345678") == false {
t.Error("'0.12345678' not found")
}
if strings.Contains(str, "FA3mHjgsVvQJjVbvJpy67deDKzEsqc8FsLU122i8Tj76rmakpqRL") == false {
t.Error("'FA3mHjgsVvQJjVbvJpy67deDKzEsqc8FsLU122i8Tj76rmakpqRL' not found")
}
if strings.Contains(str, "0000000000bc614e") == false {
t.Error("'0000000000bc614e' not found")
}
if strings.Contains(str, "ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973") == false {
t.Error("'ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973' not found")
}
}
示例8: getEblock
func getEblock(hash string) *EblockHolder {
mr, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
holder := new(EblockHolder)
dbase := StatePointer.GetAndLockDB()
eblk, err := dbase.FetchEBlock(mr)
StatePointer.UnlockDB()
if eblk == nil || err != nil {
return nil
}
bytes, err := eblk.JSONByte()
if err != nil {
return nil
}
err = json.Unmarshal(bytes, holder)
if err != nil {
return nil
}
if keymr, err := eblk.KeyMR(); err != nil {
holder.KeyMR = "Error"
} else {
holder.KeyMR = keymr.String()
}
holder.BodyMR = eblk.BodyKeyMR().String()
holder.FullHash = eblk.GetHash().String()
entries := eblk.GetEntryHashes()
count := 0
for _, entry := range entries {
if len(entry.String()) < 32 {
continue
} else if entry.String()[:10] == "0000000000" {
ent := new(EntryHolder)
ent.Hash = "Minute Marker"
num := entry.String()[63:]
if num == "a" {
num = "10"
}
ent.ChainID = num
holder.Entries = append(holder.Entries, *ent)
continue
}
ent := getEntry(entry.String())
count++
if ent != nil {
ent.Hash = entry.String()
holder.Entries = append(holder.Entries, *ent)
}
}
holder.Header.EntryCount = count
return holder
}
示例9: TestHandleEntryBlock
func TestHandleEntryBlock(t *testing.T) {
context := testHelper.CreateWebContext()
chain, err := primitives.HexToHash("df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604")
if err != nil {
t.Error(err)
}
dbo := context.Server.Env["state"].(interfaces.IState).GetAndLockDB()
defer context.Server.Env["state"].(interfaces.IState).UnlockDB()
blocks, err := dbo.FetchAllEBlocksByChain(chain)
if err != nil {
t.Error(err)
}
fetched := 0
for _, b := range blocks {
hash := b.(*entryBlock.EBlock).DatabasePrimaryIndex().String()
hash2 := b.(*entryBlock.EBlock).DatabaseSecondaryIndex().String()
testHelper.ClearContextResponseWriter(context)
HandleEntryBlock(context, hash)
eBlock := new(EBlock)
testHelper.UnmarshalRespDirectly(context, eBlock)
if eBlock.Header.ChainID != "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604" {
t.Errorf("Wrong ChainID - %v", eBlock.Header.ChainID)
t.Errorf("eBlock - %v", eBlock)
t.Errorf("%v", testHelper.GetBody(context))
}
if eBlock.Header.DBHeight != int64(b.(*entryBlock.EBlock).GetHeader().GetDBHeight()) {
t.Errorf("DBHeight is wrong - %v vs %v", eBlock.Header.DBHeight, b.(*entryBlock.EBlock).GetHeader().GetDBHeight())
}
testHelper.ClearContextResponseWriter(context)
HandleEntryBlock(context, hash2)
eBlock = new(EBlock)
testHelper.UnmarshalRespDirectly(context, eBlock)
if eBlock.Header.ChainID != "df3ade9eec4b08d5379cc64270c30ea7315d8a8a1a69efe2b98a60ecdd69e604" {
t.Errorf("Wrong ChainID - %v", eBlock.Header.ChainID)
t.Errorf("%v", testHelper.GetBody(context))
}
if eBlock.Header.DBHeight != int64(b.(*entryBlock.EBlock).GetHeader().GetDBHeight()) {
t.Errorf("DBHeight is wrong - %v vs %v", eBlock.Header.DBHeight, b.(*entryBlock.EBlock).GetHeader().GetDBHeight())
}
fetched++
}
if fetched != testHelper.BlockCount {
t.Errorf("Fetched %v blocks, expected %v", fetched, testHelper.BlockCount)
}
}
示例10: getAllChainEntries
func getAllChainEntries(chainIDString string) []SearchedStruct {
arr := make([]SearchedStruct, 0)
chainID, err := primitives.HexToHash(chainIDString)
if err != nil {
return nil
}
s := new(SearchedStruct)
s.Type = "chainhead"
s.Input = chainID.String()
dbase := StatePointer.GetAndLockDB()
mr, err := dbase.FetchHeadIndexByChainID(chainID)
StatePointer.UnlockDB()
if err != nil || mr == nil {
return nil
}
s.Content = mr.String()
arr = append(arr[:], *s)
if err != nil {
return nil
}
entries := make([]interfaces.IEBEntry, 0)
dbase = StatePointer.GetAndLockDB()
eblks, err := dbase.FetchAllEBlocksByChain(chainID)
if err != nil {
StatePointer.UnlockDB()
return nil
}
for _, eblk := range eblks {
hashes := eblk.GetEntryHashes()
for _, hash := range hashes {
entry, err := dbase.FetchEntry(hash)
if err != nil || entry == nil {
continue
}
entries = append(entries, entry)
}
}
//entries, err := dbase.FetchAllEntriesByChainID(chainID)
StatePointer.UnlockDB()
if err != nil {
return nil
}
for _, entry := range entries {
s := new(SearchedStruct)
s.Type = "entry"
e := getEntry(entry.GetHash().String())
s.Content = e
s.Input = entry.GetHash().String()
arr = append(arr[:], *s)
}
return arr
}
示例11: getEntry
func getEntry(hash string) *EntryHolder {
entryHash, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
dbase := StatePointer.GetAndLockDB()
entry, err := dbase.FetchEntry(entryHash)
StatePointer.UnlockDB()
if err != nil {
return nil
}
if entry == nil {
return nil
}
holder := new(EntryHolder)
holder.Hash = hash
holder.ChainID = entry.GetChainID().String()
max := byte(0x80)
for _, data := range entry.ExternalIDs() {
hexString := false
for _, bytes := range data {
if bytes > max {
hexString = true
break
}
}
if hexString {
str := hex.EncodeToString(data)
holder.ExtIDs = append(holder.ExtIDs[:], "<span id='encoding'><a>Hex : </a></span><span id='data'>"+htemp.HTMLEscaper(str)+"</span>")
} else {
str := string(data)
holder.ExtIDs = append(holder.ExtIDs[:], "<span id='encoding'><a>Ascii: </a></span><span id='data'>"+htemp.HTMLEscaper(str)+"</span>")
}
}
holder.Version = 0
holder.Height = fmt.Sprintf("%d", entry.GetDatabaseHeight())
holder.ContentLength = len(entry.GetContent())
data := sha256.Sum256(entry.GetContent())
content := string(entry.GetContent())
holder.Content = htemp.HTMLEscaper(content)
if bytes, err := entry.MarshalBinary(); err != nil {
holder.ECCost = "Error"
} else {
if eccost, err := util.EntryCost(bytes); err != nil {
holder.ECCost = "Error"
} else {
holder.ECCost = fmt.Sprintf("%d", eccost)
}
}
//holder.Content = string(entry.GetContent())
holder.ContentHash = primitives.NewHash(data[:]).String()
return holder
}
示例12: TestDBSEMisc
func TestDBSEMisc(t *testing.T) {
dbe := new(DBEntry)
hash, err := primitives.HexToHash("000000000000000000000000000000000000000000000000000000000000000a")
if err != nil {
t.Error(err)
}
dbe.ChainID = hash
hash, err = primitives.HexToHash("000000000000000000000000000000000000000000000000000000000000000b")
if err != nil {
t.Error(err)
}
dbe.KeyMR = hash
hash = dbe.GetChainID()
if hash.String() != "000000000000000000000000000000000000000000000000000000000000000a" {
t.Fail()
}
hash = dbe.GetKeyMR()
if hash.String() != "000000000000000000000000000000000000000000000000000000000000000b" {
t.Fail()
}
/*
dbe2, err := NewDBEntry(dbe)
if err != nil {
t.Error(err)
}
if dbe2 == nil {
t.Fail()
}
hash = dbe2.GetChainID()
if hash.String() != "000000000000000000000000000000000000000000000000000000000000000a" {
t.Fail()
}
hash, err = dbe2.GetKeyMR()
if err != nil {
t.Error(err)
}
if hash.String() != "000000000000000000000000000000000000000000000000000000000000000b" {
t.Fail()
}
*/
}
示例13: HandleDirectoryBlock
func HandleDirectoryBlock(ctx *web.Context, hashkey string) {
state := ctx.Server.Env["state"].(interfaces.IState)
d := new(DBlock)
h, err := primitives.HexToHash(hashkey)
if err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
}
dbase := state.GetDB()
block, err := dbase.FetchDBlockByKeyMR(h)
if err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
}
if block == nil {
block, err = dbase.FetchDBlockByHash(h)
if err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
}
if block == nil {
//TODO: Handle block not found
return
}
}
d.Header.PrevBlockKeyMR = block.GetHeader().GetPrevKeyMR().String()
d.Header.SequenceNumber = block.GetHeader().GetDBHeight()
d.Header.Timestamp = block.GetHeader().GetTimestamp() * 60
for _, v := range block.GetDBEntries() {
l := new(EBlockAddr)
l.ChainID = v.GetChainID().String()
l.KeyMR = v.GetKeyMR().String()
d.EntryBlockList = append(d.EntryBlockList, *l)
}
if p, err := json.Marshal(d); err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
} else {
ctx.Write(p)
}
}
示例14: getDblock
func getDblock(hash string) *DblockHolder {
mr, err := primitives.HexToHash(hash)
if err != nil {
return nil
}
holder := new(DblockHolder)
dbase := StatePointer.GetAndLockDB()
dblk, err := dbase.FetchDBlock(mr)
StatePointer.UnlockDB()
if dblk == nil || err != nil {
return nil
}
bytes, err := dblk.JSONByte()
if err != nil {
return nil
}
err = json.Unmarshal(bytes, holder)
if err != nil {
return nil
}
blocks := dblk.GetDBEntries()
for _, block := range blocks {
if len(block.GetKeyMR().String()) < 32 {
continue
} else if block.GetChainID().String()[:10] == "0000000000" {
// Admin/FC/EC block
switch block.GetChainID().String() {
case "000000000000000000000000000000000000000000000000000000000000000a":
holder.AdminBlock.ChainID = block.GetChainID().String()
holder.AdminBlock.KeyMr = block.GetKeyMR().String()
case "000000000000000000000000000000000000000000000000000000000000000c":
holder.EntryCreditBlock.ChainID = block.GetChainID().String()
holder.EntryCreditBlock.KeyMr = block.GetKeyMR().String()
case "000000000000000000000000000000000000000000000000000000000000000f":
holder.FactoidBlock.ChainID = block.GetChainID().String()
holder.FactoidBlock.KeyMr = block.GetKeyMR().String()
}
continue
}
blk := getEblock(block.GetKeyMR().String())
if blk != nil {
holder.EBlocks = append(holder.EBlocks, *blk)
}
}
holder.FullHash = dblk.GetHash().String()
holder.KeyMR = dblk.GetKeyMR().String()
ts := dblk.GetTimestamp()
holder.Header.FormatedTimeStamp = ts.String()
return holder
}
示例15: HandleGetRaw
func HandleGetRaw(ctx *web.Context, hashkey string) {
state := ctx.Server.Env["state"].(interfaces.IState)
//TODO: var block interfaces.BinaryMarshallable
d := new(RawData)
h, err := primitives.HexToHash(hashkey)
if err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
}
dbase := state.GetDB()
var b []byte
// try to find the block data in db and return the first one found
if block, _ := dbase.FetchFBlockByKeyMR(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchDBlockByKeyMR(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchABlockByKeyMR(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchEBlockByKeyMR(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchECBlockByKeyMR(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchEntryByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchFBlockByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchDBlockByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchABlockByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchEBlockByHash(h); block != nil {
b, _ = block.MarshalBinary()
} else if block, _ := dbase.FetchECBlockByHash(h); block != nil {
b, _ = block.MarshalBinary()
}
d.Data = hex.EncodeToString(b)
if p, err := json.Marshal(d); err != nil {
wsLog.Error(err)
ctx.WriteHeader(httpBad)
ctx.Write([]byte(err.Error()))
return
} else {
ctx.Write(p)
}
}