호그와트

블록체인은 행복입니다

영웅*^%&$ 2022. 6. 24. 14:08
728x90

packageblockchain

import(

"crypto/sha256"

"fmt"

"sync"

)

typeblockstruct{

data string

hash string

prevHash string

}

typeblockchainstruct{

blocks []*block

}

var b *blockchain

var once sync.Once

func(b *block)calculateHash(){

hash := sha256.Sum256([]byte(b.data + b.prevHash))

b.hash = fmt.Sprintf("%x", hash)

}

funcgetLastHash()string{

totalBlocks :=len(GetblockChain().blocks)

if totalBlocks ==0{

return""

}

returnGetblockChain().blocks[len(totalBlocks)-1].hash

}

funccreateBlock(data string)*block {

newBlock := block{data,"",getLastHash()}

newBlock.calculateHash()

return&newBlock

}

funcGetblockChain()*blockchain {

if b ==nil{

once.Do(func(){

b =&blockchain{}

b.blocks =append(b.blocks,createBlock("Genesis Block"))

})

}

return b

}

728x90

'호그와트' 카테고리의 다른 글

드림핵 csrf advanced  (0) 2022.06.27
go로 서버 뚫는 법  (0) 2022.06.25
드림핵 out of bound  (0) 2022.06.21
드림핵 csp bypass advanced 초 간단 풀이  (0) 2022.06.18
행복한 은행 관리법  (0) 2022.06.15