區塊鏈本質上是一種有序,反向連結連結串列的資料結構。block按照插入的順序存放,同時每個block都儲存指向一個儲存連結。這種結構保證可以快速獲取最新插入的block同時獲取他的hash值,而且很高效。
public class Blockchain
{
private List <Block>blockList;
public Blockchain List<Block>blockList;
this.blockList=blockList;
}
public void addBlock(String data)
Block previousBlock=blockList.get(blockList.size()-1);
this.addBlock(Block.newBlock(previousBlock.getHash() ,data) );
public void addBlock(Block block)
this.blockList.add(block);
public static Block newGenesisBlock()
return Block.newBlock(" ","Genesis Block");
public static Blockchain newBlockchain()
List<Block>blocks=new linkedList<>();
blocks.add(Block.newGenesisBlock());
return new Blockchain(blocks);
區塊鏈本質上是一種有序,反向連結連結串列的資料結構。block按照插入的順序存放,同時每個block都儲存指向一個儲存連結。這種結構保證可以快速獲取最新插入的block同時獲取他的hash值,而且很高效。
區塊資料結構public class Blockchain
{
private List <Block>blockList;
public Blockchain List<Block>blockList;
this.blockList=blockList;
}
新增區塊public void addBlock(String data)
{
Block previousBlock=blockList.get(blockList.size()-1);
this.addBlock(Block.newBlock(previousBlock.getHash() ,data) );
}
public void addBlock(Block block)
{
this.blockList.add(block);
}
建立區塊public static Block newGenesisBlock()
{
return Block.newBlock(" ","Genesis Block");
}
建立區塊鏈public static Blockchain newBlockchain()
{
List<Block>blocks=new linkedList<>();
blocks.add(Block.newGenesisBlock());
return new Blockchain(blocks);
}