-
Notifications
You must be signed in to change notification settings - Fork 5
/
main-helper.rkt
33 lines (27 loc) · 1.13 KB
/
main-helper.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#lang racket
(require "./src/blockchain.rkt")
(require "./src/utils.rkt")
(require (only-in sha bytes->hex-string))
(define (format-transaction t)
(format "...~a... sends ...~a... an amount of ~a."
(substring (wallet-public-key (transaction-from t)) 64 80)
(substring (wallet-public-key (transaction-to t)) 64 80)
(transaction-value t)))
(define (print-block bl)
(printf "Block information\n=================\nHash:\t~a\nHash_p:\t~a\nStamp:\t~a\nNonce:\t~a\nData:\t~a\n"
(block-hash bl)
(block-previous-hash bl)
(block-timestamp bl)
(block-nonce bl)
(format-transaction (block-transaction bl))))
(define (print-blockchain b)
(for ([block (blockchain-blocks b)])
(print-block block)
(newline)))
(define (print-wallets b wallet-a wallet-b)
(printf "\nWallet A balance: ~a\nWallet B balance: ~a\n\n"
(balance-wallet-blockchain b wallet-a)
(balance-wallet-blockchain b wallet-b)))
(provide (all-from-out "./src/blockchain.rkt")
(all-from-out "./src/utils.rkt")
format-transaction print-block print-blockchain print-wallets)