mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
changes for tracing the blockchain profile image not shown
This commit is contained in:
@@ -15,7 +15,6 @@ package blockchain
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
@@ -39,14 +38,10 @@ func DecodeBlockRecordProfile(recordsRaw []BlockRecordRaw) (fields []BlockRecord
|
||||
}
|
||||
|
||||
fieldType := binary.LittleEndian.Uint16(record.Data[0:2])
|
||||
fmt.Println(record.Data[0:2])
|
||||
fmt.Println(fieldType)
|
||||
fieldMap[fieldType] = record.Data[2:]
|
||||
}
|
||||
|
||||
for fieldType, fieldData := range fieldMap {
|
||||
fmt.Println("type value added")
|
||||
fmt.Println(fieldType)
|
||||
fields = append(fields, BlockRecordProfile{Type: fieldType, Data: fieldData})
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ package blockchain
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/PeernetOfficial/core/btcec"
|
||||
@@ -273,11 +274,18 @@ func (multi *MultiStore) IngestBlock(header *MultiBlockchainHeader, blockNumber
|
||||
// decode it
|
||||
decoded, status, err := DecodeBlockRaw(raw)
|
||||
if failIfInvalid && err != nil {
|
||||
fmt.Println("---- block invalid -----")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("updated")
|
||||
|
||||
// store the transferred block in the cache
|
||||
multi.WriteBlock(header.PublicKey, header.Version, blockNumber, raw)
|
||||
err = multi.WriteBlock(header.PublicKey, header.Version, blockNumber, raw)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
header.ListBlocks = append(header.ListBlocks, blockNumber)
|
||||
|
||||
// update blockchain header stats if records were decoded
|
||||
@@ -285,6 +293,13 @@ func (multi *MultiStore) IngestBlock(header *MultiBlockchainHeader, blockNumber
|
||||
multi.UpdateBlockchainStatistics(header, decoded.RecordsDecoded)
|
||||
}
|
||||
|
||||
for _, recordRaw := range decoded.RecordsRaw {
|
||||
if recordRaw.Type == 0 {
|
||||
fmt.Println("Profile update detected")
|
||||
}
|
||||
}
|
||||
fmt.Println("---------")
|
||||
|
||||
// update the blockchain header
|
||||
multi.WriteBlockchainHeader(header)
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ Author: Peter Kleissner
|
||||
|
||||
package blockchain
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ProfileReadField reads the specified profile field. See ProfileX for the list of recognized fields. The encoding depends on the field type. Status is StatusX.
|
||||
func (blockchain *Blockchain) ProfileReadField(index uint16) (data []byte, status int) {
|
||||
found := false
|
||||
@@ -44,8 +42,6 @@ func (blockchain *Blockchain) ProfileReadField(index uint16) (data []byte, statu
|
||||
func (blockchain *Blockchain) ProfileList() (fields []BlockRecordProfile, status int) {
|
||||
uniqueFields := make(map[uint16][]byte)
|
||||
|
||||
fmt.Println(blockchain.height)
|
||||
|
||||
status = blockchain.Iterate(func(block *Block) (statusI int) {
|
||||
fields, err := DecodeBlockRecordProfile(block.RecordsRaw)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,10 +8,9 @@ package webapi
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"github.com/PeernetOfficial/core/blockchain"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/PeernetOfficial/core/blockchain"
|
||||
)
|
||||
|
||||
type apiBlockchainHeader struct {
|
||||
|
||||
@@ -98,26 +98,6 @@ func (api *WebapiInstance) GreedySearchMergeDirection(nodeID *[][]byte, fileType
|
||||
|
||||
var filesFromPeer uint64
|
||||
|
||||
//var Name string
|
||||
//
|
||||
//ProfileNameFound := false
|
||||
//
|
||||
//// First iteration of the entire blockchain to search for the profile
|
||||
//// image and Username of the user
|
||||
//for blockN1 := peer.BlockchainHeight - 1; blockN1 > 0; blockN1-- {
|
||||
// blockDecoded, _, found, _ := api.Backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN1)
|
||||
// if !found {
|
||||
// continue
|
||||
// }
|
||||
// // Adding profile image and Username to the output
|
||||
// for raw := range blockDecoded.Block.RecordsRaw {
|
||||
// if blockDecoded.Block.RecordsRaw[raw].Type == blockchain.ProfileName && !ProfileNameFound {
|
||||
// Name = string(blockDecoded.Block.RecordsRaw[raw].Data[:])
|
||||
// ProfileNameFound = true
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// decode blocks from top down
|
||||
for blockN := peer.BlockchainHeight - 1; blockN > 0; blockN-- {
|
||||
blockDecoded, _, found, _ := api.Backend.ReadBlock(peer.PublicKey, peer.BlockchainVersion, blockN)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/PeernetOfficial/core/blockchain"
|
||||
)
|
||||
@@ -47,33 +48,26 @@ func (api *WebapiInstance) apiProfileList(w http.ResponseWriter, r *http.Request
|
||||
if valid && !bytes.Equal(NodeID, api.Backend.SelfNodeID()) {
|
||||
//_, node, _ := api.Backend.FindNode(NodeID, 100)
|
||||
|
||||
peers := api.Backend.PeerlistGet()
|
||||
_, peers, _ := api.Backend.FindNode(NodeID, time.Second*5)
|
||||
// First iteration of the entire blockchain to search for the profile
|
||||
// image and Username of the user
|
||||
|
||||
for i, _ := range peers {
|
||||
if bytes.Equal(peers[i].NodeID, NodeID) {
|
||||
// First iteration of the entire blockchain to search for the profile
|
||||
// image and Username of the user
|
||||
for blockN1 := peers.BlockchainHeight; blockN1 > 0; blockN1-- {
|
||||
blockDecoded, _, found, _ := api.Backend.ReadBlock(peers.PublicKey, peers.BlockchainVersion, blockN1)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
|
||||
for blockN1 := peers[i].BlockchainHeight - 1; blockN1 > 0; blockN1-- {
|
||||
blockDecoded, _, found, _ := peers[i].Backend.ReadBlock(peers[i].PublicKey, peers[i].BlockchainVersion, blockN1)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
profile, _ := blockchain.DecodeBlockRecordProfile(blockDecoded.Block.RecordsRaw)
|
||||
// Adding profile image and Username to the output
|
||||
for raw, _ := range profile {
|
||||
|
||||
profile, _ := blockchain.DecodeBlockRecordProfile(blockDecoded.Block.RecordsRaw)
|
||||
// Adding profile image and Username to the output
|
||||
for raw, _ := range profile {
|
||||
|
||||
if profile[raw].Type == blockchain.ProfileName {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: profile[raw].Type, Data: profile[raw].Data[:]}))
|
||||
}
|
||||
if profile[raw].Type == blockchain.ProfilePicture {
|
||||
result.Status = 0
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: profile[raw].Type, Data: profile[raw].Data[:]}))
|
||||
}
|
||||
}
|
||||
if profile[raw].Type == blockchain.ProfileName {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: profile[raw].Type, Data: profile[raw].Data[:]}))
|
||||
}
|
||||
if profile[raw].Type == blockchain.ProfilePicture {
|
||||
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: profile[raw].Type, Data: profile[raw].Data[:]}))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +129,6 @@ func (api *WebapiInstance) apiProfileWrite(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
for _, field := range input.Fields {
|
||||
api.Backend.LogError("apiProfileWrite(", "Upload type: %v\n", field.Type)
|
||||
}
|
||||
|
||||
var fields []blockchain.BlockRecordProfile
|
||||
|
||||
for n := range input.Fields {
|
||||
@@ -147,6 +137,8 @@ func (api *WebapiInstance) apiProfileWrite(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
newHeight, newVersion, status := api.Backend.UserBlockchain.ProfileWrite(fields)
|
||||
|
||||
api.Backend.LogError("apiProfileWrite", "Height: %v, Version %v", newHeight, newVersion)
|
||||
|
||||
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user