本文整理匯總了Golang中github.com/FactomProject/factoid/block.FBlock類的典型用法代碼示例。如果您正苦於以下問題:Golang FBlock類的具體用法?Golang FBlock怎麽用?Golang FBlock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FBlock類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchAllFBlocks
// FetchAllFBlocks gets all of the factoid blocks
func (db *LevelDb) FetchAllFBlocks() (FBlocks []block.IFBlock, err error) {
db.dbLock.Lock()
defer db.dbLock.Unlock()
var fromkey []byte = []byte{byte(TBL_SC)} // Table Name (1 bytes) // Timestamp (8 bytes)
var tokey []byte = []byte{byte(TBL_SC + 1)} // Table Name (1 bytes)
FBlockSlice := make([]block.IFBlock, 0, 10)
iter := db.lDb.NewIterator(&util.Range{Start: fromkey, Limit: tokey}, db.ro)
for iter.Next() {
FBlock := new(block.FBlock)
_, err := FBlock.UnmarshalBinaryData(iter.Value())
if err != nil {
return nil, err
}
FBlockSlice = append(FBlockSlice, FBlock)
}
iter.Release()
err = iter.Error()
return FBlockSlice, nil
}
示例2: getAll
func getAll() error {
dbs := make([]*common.DirectoryBlock, 0, 100)
next := DBHeadStr
for {
blk, err := factom.GetRaw(next)
if err != nil {
panic(err.Error())
}
db := new(common.DirectoryBlock)
err = db.UnmarshalBinary(blk)
if err != nil {
panic(err.Error())
}
dbs = append(dbs, db)
if bytes.Equal(db.Header.PrevKeyMR.Bytes(), DBHeadLast) {
break
}
next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
}
DBHeadLast = DBHead
for i := len(dbs) - 1; i >= 0; i-- {
DirectoryBlocks = append(DirectoryBlocks, dbs[i])
fb := new(block.FBlock)
var fcnt int
for _, dbe := range dbs[i].DBEntries {
if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
fcnt++
hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
fdata, err := factom.GetRaw(hashstr)
if err != nil {
panic(err.Error())
}
err = fb.UnmarshalBinary(fdata)
if err != nil {
panic(err.Error())
}
FactoidBlocks = append(FactoidBlocks, fb)
break
}
}
if fb == nil {
panic("Missing Factoid Block from a directory block")
}
if fcnt > 1 {
panic("More than one Factom Block found in a directory block.")
}
if err := ProcessFB(fb); err != nil {
return err
}
}
return nil
}
示例3: getAll
func getAll() error {
dbs := make([]*common.DirectoryBlock, 0, 100)
next := DBHeadStr
for {
blk, err := factom.GetRaw(next)
if err != nil {
panic(err.Error())
}
db := new(common.DirectoryBlock)
err = db.UnmarshalBinary(blk)
if err != nil {
panic(err.Error())
}
dbs = append(dbs, db)
if bytes.Equal(db.Header.PrevKeyMR.Bytes(), common.ZERO_HASH[:]) {
break
}
next = hex.EncodeToString(db.Header.PrevKeyMR.Bytes())
}
for i := len(dbs) - 1; i >= 0; i-- {
DirectoryBlocks = append(DirectoryBlocks, dbs[i])
fb := new(block.FBlock)
for _, dbe := range dbs[i].DBEntries {
if bytes.Equal(dbe.ChainID.Bytes(), common.FACTOID_CHAINID) {
hashstr := hex.EncodeToString(dbe.KeyMR.Bytes())
fdata, err := factom.GetRaw(hashstr)
if err != nil {
panic(err.Error())
}
err = fb.UnmarshalBinary(fdata)
if err != nil {
panic(err.Error())
}
FactoidBlocks = append(FactoidBlocks, fb)
break
}
}
if fb == nil {
fmt.Println("Missing Factoid Block")
}
}
return nil
}
示例4: Test_create_genesis_FactoidState
//.........這裏部分代碼省略.........
if addtest && good && err != nil {
fmt.Println(err)
fmt.Println("Unmarshal Failed. trans is good",
"\nand the error detected: ", err,
"\nand k:", k, "and flip:", flip)
test.Fail()
return
}
if good && addtest {
PrtTrans(t)
fs.stats.transactions += 1
title := fmt.Sprintf("Bad Transactions: %d Total transaactions %d",
fs.stats.badAddresses, fs.stats.transactions)
cp.CP.AddUpdate("Bad Transaction", "status", title, "", 0)
time.Sleep(time.Second / 100)
} else {
fs.stats.badAddresses += 1
}
}
//
// Serialization deserialization tests for blocks
//
blkdata, err := fs.GetCurrentBlock().MarshalBinary()
if err != nil {
test.Fail()
return
}
blk := fs.GetCurrentBlock().GetNewInstance().(block.IFBlock)
err = blk.UnmarshalBinary(blkdata)
if err != nil {
test.Fail()
return
}
if len(blkdata) > maxblk {
maxblk = len(blkdata)
cp.CP.AddUpdate(
"maxblocksize", // tag
"info", // Category
fmt.Sprintf("Max Block Size: %dK", maxblk/1024), // Title
"", // Msg
0) // Expires
}
sec1 := fs.stats.TransactionsPerSec()
sec2 := fs.stats.TotalTransactionsPerSec()
cp.CP.AddUpdate(
"transpersec", // tag
"info", // Category
fmt.Sprintf("Transactions per second %4.2f, (+ bad) %4.2f", sec1, sec2), // Title
"", // Msg
0) // Expires
fmt.Println("Block Check")
blk1 := fs.GetCurrentBlock()
blk1MR := fs.GetCurrentBlock().GetHash()
fmt.Println("ProcessEndOfBlock")
fs.ProcessEndOfBlock() // Process the block.
fmt.Println("Check ProcessEndOfBlock")
blk2PMR := fs.GetCurrentBlock().GetPrevKeyMR()
if !bytes.Equal(blk1MR.Bytes(), blk2PMR.Bytes()) {
fmt.Println("MR's don't match")
test.Fail()
示例5: ParseFactoidBlock
func ParseFactoidBlock(chainID, hash string, rawBlock []byte, blockTime string) (*Block, error) {
answer := new(Block)
fBlock := new(block.FBlock)
_, err := fBlock.UnmarshalBinaryData(rawBlock)
if err != nil {
return nil, err
}
answer.ChainID = chainID
answer.PartialHash = fBlock.GetHash().String()
answer.FullHash = fBlock.GetLedgerKeyMR().String()
answer.PrevBlockHash = fmt.Sprintf("%x", fBlock.PrevKeyMR.Bytes())
transactions := fBlock.GetTransactions()
answer.EntryCount = len(transactions)
answer.EntryList = make([]*Entry, answer.EntryCount)
answer.BinaryString = fmt.Sprintf("%x", rawBlock)
for i, v := range transactions {
entry := new(Entry)
bin, err := v.MarshalBinary()
if err != nil {
return nil, err
}
entry.BinaryString = fmt.Sprintf("%x", bin)
entry.Timestamp = TimestampToString(v.GetMilliTimestamp() / 1000)
entry.Hash = v.GetHash().String()
entry.ChainID = chainID
entry.JSONString, err = v.JSONString()
if err != nil {
return nil, err
}
entry.SpewString = v.Spew()
answer.EntryList[i] = entry
}
answer.JSONString, err = fBlock.JSONString()
if err != nil {
return nil, err
}
answer.SpewString = fBlock.Spew()
answer.IsFactoidBlock = true
return answer, nil
}
示例6: Test_create_block
func Test_create_block(test *testing.T) {
w := new(wallet.SCWallet) // make me a wallet
w.Init()
w.NewSeed([]byte("slfkjasdlfjasflajsfl"))
scb := block.NewFBlock(1000, 0)
cb := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000))
scb.AddCoinbase(cb)
for i := 0; i < 3; i++ {
h0, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-0"), 1, 1)
if err != nil {
sc.Prtln("Error 1")
test.Fail()
}
h1, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-1"), 1, 1)
if err != nil {
sc.Prtln("Error 2")
test.Fail()
}
h2, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-2"), 1, 1)
if err != nil {
sc.Prtln("Error 3")
test.Fail()
}
h3, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-3"), 1, 1)
if err != nil {
sc.Prtln("Error 4")
test.Fail()
}
h4, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-4"), 1, 1)
if err != nil {
sc.Prtln("Error 5")
test.Fail()
}
h5, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-5"), 1, 1)
if err != nil {
sc.Prtln("Error 6")
test.Fail()
}
t := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000))
w.AddInput(t, h1, 1000000)
w.AddInput(t, h2, 1000000)
w.AddOutput(t, h3, 1000000)
w.AddOutput(t, h4, 500000)
w.AddECOutput(t, h5, 500000)
w.AddInput(t, h0, 0)
fee, err := t.CalculateFee(1000)
w.UpdateInput(t, 2, h0, fee)
signed, err := w.SignInputs(t)
if err != nil {
sc.Prtln("Error found: ", err)
test.Fail()
return
}
if !signed {
sc.Prtln("Not valid")
test.Fail()
return
}
err = scb.AddTransaction(t)
if err != nil {
sc.Prtln("Error found: ", err)
test.Fail()
return
}
}
data, err := scb.MarshalBinary()
if err != nil {
fmt.Println(err)
test.Fail()
return
}
scb2 := new(block.FBlock)
_, err = scb2.UnmarshalBinaryData(data)
fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", scb2)
if err != nil {
fmt.Println(err)
test.Fail()
return
}
//sc.Prtln("FIRST\n",scb,"SECOND\n",scb2)
if scb.IsEqual(scb2) != nil {
fmt.Println(err)
test.Fail()
return
}
}