├── README.md
├── 代币底层实现
├── 01.比特币钱包的实现
│ ├── 01.比特币钱包.md
│ ├── golang.org
│ │ └── x
│ │ │ └── crypto
│ │ │ ├── .gitattributes
│ │ │ ├── .gitignore
│ │ │ ├── AUTHORS
│ │ │ ├── CONTRIBUTING.md
│ │ │ ├── CONTRIBUTORS
│ │ │ ├── LICENSE
│ │ │ ├── PATENTS
│ │ │ ├── README.md
│ │ │ ├── acme
│ │ │ ├── acme.go
│ │ │ ├── acme_test.go
│ │ │ ├── autocert
│ │ │ │ ├── autocert.go
│ │ │ │ ├── autocert_test.go
│ │ │ │ ├── cache.go
│ │ │ │ ├── cache_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── internal
│ │ │ │ │ └── acmetest
│ │ │ │ │ │ └── ca.go
│ │ │ │ ├── listener.go
│ │ │ │ ├── renewal.go
│ │ │ │ └── renewal_test.go
│ │ │ ├── http.go
│ │ │ ├── http_test.go
│ │ │ ├── jws.go
│ │ │ ├── jws_test.go
│ │ │ ├── types.go
│ │ │ └── types_test.go
│ │ │ ├── argon2
│ │ │ ├── argon2.go
│ │ │ ├── argon2_test.go
│ │ │ ├── blake2b.go
│ │ │ ├── blamka_amd64.go
│ │ │ ├── blamka_amd64.s
│ │ │ ├── blamka_generic.go
│ │ │ └── blamka_ref.go
│ │ │ ├── bcrypt
│ │ │ ├── base64.go
│ │ │ ├── bcrypt.go
│ │ │ └── bcrypt_test.go
│ │ │ ├── blake2b
│ │ │ ├── blake2b.go
│ │ │ ├── blake2bAVX2_amd64.go
│ │ │ ├── blake2bAVX2_amd64.s
│ │ │ ├── blake2b_amd64.go
│ │ │ ├── blake2b_amd64.s
│ │ │ ├── blake2b_generic.go
│ │ │ ├── blake2b_ref.go
│ │ │ ├── blake2b_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blake2s
│ │ │ ├── blake2s.go
│ │ │ ├── blake2s_386.go
│ │ │ ├── blake2s_386.s
│ │ │ ├── blake2s_amd64.go
│ │ │ ├── blake2s_amd64.s
│ │ │ ├── blake2s_generic.go
│ │ │ ├── blake2s_ref.go
│ │ │ ├── blake2s_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blowfish
│ │ │ ├── block.go
│ │ │ ├── blowfish_test.go
│ │ │ ├── cipher.go
│ │ │ └── const.go
│ │ │ ├── bn256
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ │ │ ├── cast5
│ │ │ ├── cast5.go
│ │ │ └── cast5_test.go
│ │ │ ├── chacha20poly1305
│ │ │ ├── chacha20poly1305.go
│ │ │ ├── chacha20poly1305_amd64.go
│ │ │ ├── chacha20poly1305_amd64.s
│ │ │ ├── chacha20poly1305_generic.go
│ │ │ ├── chacha20poly1305_noasm.go
│ │ │ ├── chacha20poly1305_test.go
│ │ │ ├── chacha20poly1305_vectors_test.go
│ │ │ └── xchacha20poly1305.go
│ │ │ ├── codereview.cfg
│ │ │ ├── cryptobyte
│ │ │ ├── asn1.go
│ │ │ ├── asn1
│ │ │ │ └── asn1.go
│ │ │ ├── asn1_test.go
│ │ │ ├── builder.go
│ │ │ ├── cryptobyte_test.go
│ │ │ ├── example_test.go
│ │ │ └── string.go
│ │ │ ├── curve25519
│ │ │ ├── const_amd64.h
│ │ │ ├── const_amd64.s
│ │ │ ├── cswap_amd64.s
│ │ │ ├── curve25519.go
│ │ │ ├── curve25519_test.go
│ │ │ ├── doc.go
│ │ │ ├── freeze_amd64.s
│ │ │ ├── ladderstep_amd64.s
│ │ │ ├── mont25519_amd64.go
│ │ │ ├── mul_amd64.s
│ │ │ └── square_amd64.s
│ │ │ ├── ed25519
│ │ │ ├── ed25519.go
│ │ │ ├── ed25519_test.go
│ │ │ ├── internal
│ │ │ │ └── edwards25519
│ │ │ │ │ ├── const.go
│ │ │ │ │ └── edwards25519.go
│ │ │ └── testdata
│ │ │ │ └── sign.input.gz
│ │ │ ├── hkdf
│ │ │ ├── example_test.go
│ │ │ ├── hkdf.go
│ │ │ └── hkdf_test.go
│ │ │ ├── internal
│ │ │ ├── chacha20
│ │ │ │ ├── chacha_generic.go
│ │ │ │ ├── chacha_noasm.go
│ │ │ │ ├── chacha_s390x.go
│ │ │ │ ├── chacha_s390x.s
│ │ │ │ ├── chacha_test.go
│ │ │ │ ├── vectors_test.go
│ │ │ │ └── xor.go
│ │ │ └── subtle
│ │ │ │ ├── aliasing.go
│ │ │ │ ├── aliasing_appengine.go
│ │ │ │ └── aliasing_test.go
│ │ │ ├── md4
│ │ │ ├── example_test.go
│ │ │ ├── md4.go
│ │ │ ├── md4_test.go
│ │ │ └── md4block.go
│ │ │ ├── nacl
│ │ │ ├── auth
│ │ │ │ ├── auth.go
│ │ │ │ ├── auth_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── box
│ │ │ │ ├── box.go
│ │ │ │ ├── box_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── secretbox
│ │ │ │ ├── example_test.go
│ │ │ │ ├── secretbox.go
│ │ │ │ └── secretbox_test.go
│ │ │ └── sign
│ │ │ │ ├── sign.go
│ │ │ │ └── sign_test.go
│ │ │ ├── ocsp
│ │ │ ├── ocsp.go
│ │ │ └── ocsp_test.go
│ │ │ ├── openpgp
│ │ │ ├── armor
│ │ │ │ ├── armor.go
│ │ │ │ ├── armor_test.go
│ │ │ │ └── encode.go
│ │ │ ├── canonical_text.go
│ │ │ ├── canonical_text_test.go
│ │ │ ├── clearsign
│ │ │ │ ├── clearsign.go
│ │ │ │ └── clearsign_test.go
│ │ │ ├── elgamal
│ │ │ │ ├── elgamal.go
│ │ │ │ └── elgamal_test.go
│ │ │ ├── errors
│ │ │ │ └── errors.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── packet
│ │ │ │ ├── compressed.go
│ │ │ │ ├── compressed_test.go
│ │ │ │ ├── config.go
│ │ │ │ ├── encrypted_key.go
│ │ │ │ ├── encrypted_key_test.go
│ │ │ │ ├── literal.go
│ │ │ │ ├── ocfb.go
│ │ │ │ ├── ocfb_test.go
│ │ │ │ ├── one_pass_signature.go
│ │ │ │ ├── opaque.go
│ │ │ │ ├── opaque_test.go
│ │ │ │ ├── packet.go
│ │ │ │ ├── packet_test.go
│ │ │ │ ├── private_key.go
│ │ │ │ ├── private_key_test.go
│ │ │ │ ├── public_key.go
│ │ │ │ ├── public_key_test.go
│ │ │ │ ├── public_key_v3.go
│ │ │ │ ├── public_key_v3_test.go
│ │ │ │ ├── reader.go
│ │ │ │ ├── signature.go
│ │ │ │ ├── signature_test.go
│ │ │ │ ├── signature_v3.go
│ │ │ │ ├── signature_v3_test.go
│ │ │ │ ├── symmetric_key_encrypted.go
│ │ │ │ ├── symmetric_key_encrypted_test.go
│ │ │ │ ├── symmetrically_encrypted.go
│ │ │ │ ├── symmetrically_encrypted_test.go
│ │ │ │ ├── userattribute.go
│ │ │ │ ├── userattribute_test.go
│ │ │ │ ├── userid.go
│ │ │ │ └── userid_test.go
│ │ │ ├── read.go
│ │ │ ├── read_test.go
│ │ │ ├── s2k
│ │ │ │ ├── s2k.go
│ │ │ │ └── s2k_test.go
│ │ │ ├── write.go
│ │ │ └── write_test.go
│ │ │ ├── otr
│ │ │ ├── libotr_test_helper.c
│ │ │ ├── otr.go
│ │ │ ├── otr_test.go
│ │ │ └── smp.go
│ │ │ ├── pbkdf2
│ │ │ ├── pbkdf2.go
│ │ │ └── pbkdf2_test.go
│ │ │ ├── pkcs12
│ │ │ ├── bmp-string.go
│ │ │ ├── bmp-string_test.go
│ │ │ ├── crypto.go
│ │ │ ├── crypto_test.go
│ │ │ ├── errors.go
│ │ │ ├── internal
│ │ │ │ └── rc2
│ │ │ │ │ ├── bench_test.go
│ │ │ │ │ ├── rc2.go
│ │ │ │ │ └── rc2_test.go
│ │ │ ├── mac.go
│ │ │ ├── mac_test.go
│ │ │ ├── pbkdf.go
│ │ │ ├── pbkdf_test.go
│ │ │ ├── pkcs12.go
│ │ │ ├── pkcs12_test.go
│ │ │ └── safebags.go
│ │ │ ├── poly1305
│ │ │ ├── poly1305.go
│ │ │ ├── poly1305_test.go
│ │ │ ├── sum_amd64.go
│ │ │ ├── sum_amd64.s
│ │ │ ├── sum_arm.go
│ │ │ ├── sum_arm.s
│ │ │ ├── sum_noasm.go
│ │ │ ├── sum_ref.go
│ │ │ ├── sum_s390x.go
│ │ │ ├── sum_s390x.s
│ │ │ ├── sum_vmsl_s390x.s
│ │ │ └── vectors_test.go
│ │ │ ├── ripemd160
│ │ │ ├── ripemd160.go
│ │ │ ├── ripemd160_test.go
│ │ │ └── ripemd160block.go
│ │ │ ├── salsa20
│ │ │ ├── salsa
│ │ │ │ ├── hsalsa20.go
│ │ │ │ ├── salsa2020_amd64.s
│ │ │ │ ├── salsa208.go
│ │ │ │ ├── salsa20_amd64.go
│ │ │ │ ├── salsa20_ref.go
│ │ │ │ └── salsa_test.go
│ │ │ ├── salsa20.go
│ │ │ └── salsa20_test.go
│ │ │ ├── scrypt
│ │ │ ├── example_test.go
│ │ │ ├── scrypt.go
│ │ │ └── scrypt_test.go
│ │ │ ├── sha3
│ │ │ ├── doc.go
│ │ │ ├── hashes.go
│ │ │ ├── hashes_generic.go
│ │ │ ├── keccakf.go
│ │ │ ├── keccakf_amd64.go
│ │ │ ├── keccakf_amd64.s
│ │ │ ├── register.go
│ │ │ ├── sha3.go
│ │ │ ├── sha3_s390x.go
│ │ │ ├── sha3_s390x.s
│ │ │ ├── sha3_test.go
│ │ │ ├── shake.go
│ │ │ ├── shake_generic.go
│ │ │ ├── testdata
│ │ │ │ └── keccakKats.json.deflate
│ │ │ ├── xor.go
│ │ │ ├── xor_generic.go
│ │ │ └── xor_unaligned.go
│ │ │ ├── ssh
│ │ │ ├── agent
│ │ │ │ ├── client.go
│ │ │ │ ├── client_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── forward.go
│ │ │ │ ├── keyring.go
│ │ │ │ ├── keyring_test.go
│ │ │ │ ├── server.go
│ │ │ │ ├── server_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── benchmark_test.go
│ │ │ ├── buffer.go
│ │ │ ├── buffer_test.go
│ │ │ ├── certs.go
│ │ │ ├── certs_test.go
│ │ │ ├── channel.go
│ │ │ ├── cipher.go
│ │ │ ├── cipher_test.go
│ │ │ ├── client.go
│ │ │ ├── client_auth.go
│ │ │ ├── client_auth_test.go
│ │ │ ├── client_test.go
│ │ │ ├── common.go
│ │ │ ├── connection.go
│ │ │ ├── doc.go
│ │ │ ├── example_test.go
│ │ │ ├── handshake.go
│ │ │ ├── handshake_test.go
│ │ │ ├── kex.go
│ │ │ ├── kex_test.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── knownhosts
│ │ │ │ ├── knownhosts.go
│ │ │ │ └── knownhosts_test.go
│ │ │ ├── mac.go
│ │ │ ├── mempipe_test.go
│ │ │ ├── messages.go
│ │ │ ├── messages_test.go
│ │ │ ├── mux.go
│ │ │ ├── mux_test.go
│ │ │ ├── server.go
│ │ │ ├── session.go
│ │ │ ├── session_test.go
│ │ │ ├── streamlocal.go
│ │ │ ├── tcpip.go
│ │ │ ├── tcpip_test.go
│ │ │ ├── terminal
│ │ │ │ ├── terminal.go
│ │ │ │ ├── terminal_test.go
│ │ │ │ ├── util.go
│ │ │ │ ├── util_bsd.go
│ │ │ │ ├── util_linux.go
│ │ │ │ ├── util_plan9.go
│ │ │ │ ├── util_solaris.go
│ │ │ │ └── util_windows.go
│ │ │ ├── test
│ │ │ │ ├── agent_unix_test.go
│ │ │ │ ├── banner_test.go
│ │ │ │ ├── cert_test.go
│ │ │ │ ├── dial_unix_test.go
│ │ │ │ ├── doc.go
│ │ │ │ ├── forward_unix_test.go
│ │ │ │ ├── multi_auth_test.go
│ │ │ │ ├── session_test.go
│ │ │ │ ├── sshd_test_pw.c
│ │ │ │ ├── test_unix_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── testdata
│ │ │ │ ├── doc.go
│ │ │ │ └── keys.go
│ │ │ ├── testdata_test.go
│ │ │ ├── transport.go
│ │ │ └── transport_test.go
│ │ │ ├── tea
│ │ │ ├── cipher.go
│ │ │ └── tea_test.go
│ │ │ ├── twofish
│ │ │ ├── twofish.go
│ │ │ └── twofish_test.go
│ │ │ ├── xtea
│ │ │ ├── block.go
│ │ │ ├── cipher.go
│ │ │ └── xtea_test.go
│ │ │ └── xts
│ │ │ ├── xts.go
│ │ │ └── xts_test.go
│ ├── images
│ │ └── bitcoinAddress.png
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── cli.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_listaddresses.go
│ │ ├── main.go
│ │ └── utils.go
├── 02.区块链数据结构的实现-1
│ ├── 02.区块链数据结构的实现-1.md
│ ├── golang.org
│ │ └── x
│ │ │ └── crypto
│ │ │ ├── .gitattributes
│ │ │ ├── .gitignore
│ │ │ ├── AUTHORS
│ │ │ ├── CONTRIBUTING.md
│ │ │ ├── CONTRIBUTORS
│ │ │ ├── LICENSE
│ │ │ ├── PATENTS
│ │ │ ├── README.md
│ │ │ ├── acme
│ │ │ ├── acme.go
│ │ │ ├── acme_test.go
│ │ │ ├── autocert
│ │ │ │ ├── autocert.go
│ │ │ │ ├── autocert_test.go
│ │ │ │ ├── cache.go
│ │ │ │ ├── cache_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── internal
│ │ │ │ │ └── acmetest
│ │ │ │ │ │ └── ca.go
│ │ │ │ ├── listener.go
│ │ │ │ ├── renewal.go
│ │ │ │ └── renewal_test.go
│ │ │ ├── http.go
│ │ │ ├── http_test.go
│ │ │ ├── jws.go
│ │ │ ├── jws_test.go
│ │ │ ├── types.go
│ │ │ └── types_test.go
│ │ │ ├── argon2
│ │ │ ├── argon2.go
│ │ │ ├── argon2_test.go
│ │ │ ├── blake2b.go
│ │ │ ├── blamka_amd64.go
│ │ │ ├── blamka_amd64.s
│ │ │ ├── blamka_generic.go
│ │ │ └── blamka_ref.go
│ │ │ ├── bcrypt
│ │ │ ├── base64.go
│ │ │ ├── bcrypt.go
│ │ │ └── bcrypt_test.go
│ │ │ ├── blake2b
│ │ │ ├── blake2b.go
│ │ │ ├── blake2bAVX2_amd64.go
│ │ │ ├── blake2bAVX2_amd64.s
│ │ │ ├── blake2b_amd64.go
│ │ │ ├── blake2b_amd64.s
│ │ │ ├── blake2b_generic.go
│ │ │ ├── blake2b_ref.go
│ │ │ ├── blake2b_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blake2s
│ │ │ ├── blake2s.go
│ │ │ ├── blake2s_386.go
│ │ │ ├── blake2s_386.s
│ │ │ ├── blake2s_amd64.go
│ │ │ ├── blake2s_amd64.s
│ │ │ ├── blake2s_generic.go
│ │ │ ├── blake2s_ref.go
│ │ │ ├── blake2s_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blowfish
│ │ │ ├── block.go
│ │ │ ├── blowfish_test.go
│ │ │ ├── cipher.go
│ │ │ └── const.go
│ │ │ ├── bn256
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ │ │ ├── cast5
│ │ │ ├── cast5.go
│ │ │ └── cast5_test.go
│ │ │ ├── chacha20poly1305
│ │ │ ├── chacha20poly1305.go
│ │ │ ├── chacha20poly1305_amd64.go
│ │ │ ├── chacha20poly1305_amd64.s
│ │ │ ├── chacha20poly1305_generic.go
│ │ │ ├── chacha20poly1305_noasm.go
│ │ │ ├── chacha20poly1305_test.go
│ │ │ ├── chacha20poly1305_vectors_test.go
│ │ │ └── xchacha20poly1305.go
│ │ │ ├── codereview.cfg
│ │ │ ├── cryptobyte
│ │ │ ├── asn1.go
│ │ │ ├── asn1
│ │ │ │ └── asn1.go
│ │ │ ├── asn1_test.go
│ │ │ ├── builder.go
│ │ │ ├── cryptobyte_test.go
│ │ │ ├── example_test.go
│ │ │ └── string.go
│ │ │ ├── curve25519
│ │ │ ├── const_amd64.h
│ │ │ ├── const_amd64.s
│ │ │ ├── cswap_amd64.s
│ │ │ ├── curve25519.go
│ │ │ ├── curve25519_test.go
│ │ │ ├── doc.go
│ │ │ ├── freeze_amd64.s
│ │ │ ├── ladderstep_amd64.s
│ │ │ ├── mont25519_amd64.go
│ │ │ ├── mul_amd64.s
│ │ │ └── square_amd64.s
│ │ │ ├── ed25519
│ │ │ ├── ed25519.go
│ │ │ ├── ed25519_test.go
│ │ │ ├── internal
│ │ │ │ └── edwards25519
│ │ │ │ │ ├── const.go
│ │ │ │ │ └── edwards25519.go
│ │ │ └── testdata
│ │ │ │ └── sign.input.gz
│ │ │ ├── hkdf
│ │ │ ├── example_test.go
│ │ │ ├── hkdf.go
│ │ │ └── hkdf_test.go
│ │ │ ├── internal
│ │ │ ├── chacha20
│ │ │ │ ├── chacha_generic.go
│ │ │ │ ├── chacha_noasm.go
│ │ │ │ ├── chacha_s390x.go
│ │ │ │ ├── chacha_s390x.s
│ │ │ │ ├── chacha_test.go
│ │ │ │ ├── vectors_test.go
│ │ │ │ └── xor.go
│ │ │ └── subtle
│ │ │ │ ├── aliasing.go
│ │ │ │ ├── aliasing_appengine.go
│ │ │ │ └── aliasing_test.go
│ │ │ ├── md4
│ │ │ ├── example_test.go
│ │ │ ├── md4.go
│ │ │ ├── md4_test.go
│ │ │ └── md4block.go
│ │ │ ├── nacl
│ │ │ ├── auth
│ │ │ │ ├── auth.go
│ │ │ │ ├── auth_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── box
│ │ │ │ ├── box.go
│ │ │ │ ├── box_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── secretbox
│ │ │ │ ├── example_test.go
│ │ │ │ ├── secretbox.go
│ │ │ │ └── secretbox_test.go
│ │ │ └── sign
│ │ │ │ ├── sign.go
│ │ │ │ └── sign_test.go
│ │ │ ├── ocsp
│ │ │ ├── ocsp.go
│ │ │ └── ocsp_test.go
│ │ │ ├── openpgp
│ │ │ ├── armor
│ │ │ │ ├── armor.go
│ │ │ │ ├── armor_test.go
│ │ │ │ └── encode.go
│ │ │ ├── canonical_text.go
│ │ │ ├── canonical_text_test.go
│ │ │ ├── clearsign
│ │ │ │ ├── clearsign.go
│ │ │ │ └── clearsign_test.go
│ │ │ ├── elgamal
│ │ │ │ ├── elgamal.go
│ │ │ │ └── elgamal_test.go
│ │ │ ├── errors
│ │ │ │ └── errors.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── packet
│ │ │ │ ├── compressed.go
│ │ │ │ ├── compressed_test.go
│ │ │ │ ├── config.go
│ │ │ │ ├── encrypted_key.go
│ │ │ │ ├── encrypted_key_test.go
│ │ │ │ ├── literal.go
│ │ │ │ ├── ocfb.go
│ │ │ │ ├── ocfb_test.go
│ │ │ │ ├── one_pass_signature.go
│ │ │ │ ├── opaque.go
│ │ │ │ ├── opaque_test.go
│ │ │ │ ├── packet.go
│ │ │ │ ├── packet_test.go
│ │ │ │ ├── private_key.go
│ │ │ │ ├── private_key_test.go
│ │ │ │ ├── public_key.go
│ │ │ │ ├── public_key_test.go
│ │ │ │ ├── public_key_v3.go
│ │ │ │ ├── public_key_v3_test.go
│ │ │ │ ├── reader.go
│ │ │ │ ├── signature.go
│ │ │ │ ├── signature_test.go
│ │ │ │ ├── signature_v3.go
│ │ │ │ ├── signature_v3_test.go
│ │ │ │ ├── symmetric_key_encrypted.go
│ │ │ │ ├── symmetric_key_encrypted_test.go
│ │ │ │ ├── symmetrically_encrypted.go
│ │ │ │ ├── symmetrically_encrypted_test.go
│ │ │ │ ├── userattribute.go
│ │ │ │ ├── userattribute_test.go
│ │ │ │ ├── userid.go
│ │ │ │ └── userid_test.go
│ │ │ ├── read.go
│ │ │ ├── read_test.go
│ │ │ ├── s2k
│ │ │ │ ├── s2k.go
│ │ │ │ └── s2k_test.go
│ │ │ ├── write.go
│ │ │ └── write_test.go
│ │ │ ├── otr
│ │ │ ├── libotr_test_helper.c
│ │ │ ├── otr.go
│ │ │ ├── otr_test.go
│ │ │ └── smp.go
│ │ │ ├── pbkdf2
│ │ │ ├── pbkdf2.go
│ │ │ └── pbkdf2_test.go
│ │ │ ├── pkcs12
│ │ │ ├── bmp-string.go
│ │ │ ├── bmp-string_test.go
│ │ │ ├── crypto.go
│ │ │ ├── crypto_test.go
│ │ │ ├── errors.go
│ │ │ ├── internal
│ │ │ │ └── rc2
│ │ │ │ │ ├── bench_test.go
│ │ │ │ │ ├── rc2.go
│ │ │ │ │ └── rc2_test.go
│ │ │ ├── mac.go
│ │ │ ├── mac_test.go
│ │ │ ├── pbkdf.go
│ │ │ ├── pbkdf_test.go
│ │ │ ├── pkcs12.go
│ │ │ ├── pkcs12_test.go
│ │ │ └── safebags.go
│ │ │ ├── poly1305
│ │ │ ├── poly1305.go
│ │ │ ├── poly1305_test.go
│ │ │ ├── sum_amd64.go
│ │ │ ├── sum_amd64.s
│ │ │ ├── sum_arm.go
│ │ │ ├── sum_arm.s
│ │ │ ├── sum_noasm.go
│ │ │ ├── sum_ref.go
│ │ │ ├── sum_s390x.go
│ │ │ ├── sum_s390x.s
│ │ │ ├── sum_vmsl_s390x.s
│ │ │ └── vectors_test.go
│ │ │ ├── ripemd160
│ │ │ ├── ripemd160.go
│ │ │ ├── ripemd160_test.go
│ │ │ └── ripemd160block.go
│ │ │ ├── salsa20
│ │ │ ├── salsa
│ │ │ │ ├── hsalsa20.go
│ │ │ │ ├── salsa2020_amd64.s
│ │ │ │ ├── salsa208.go
│ │ │ │ ├── salsa20_amd64.go
│ │ │ │ ├── salsa20_ref.go
│ │ │ │ └── salsa_test.go
│ │ │ ├── salsa20.go
│ │ │ └── salsa20_test.go
│ │ │ ├── scrypt
│ │ │ ├── example_test.go
│ │ │ ├── scrypt.go
│ │ │ └── scrypt_test.go
│ │ │ ├── sha3
│ │ │ ├── doc.go
│ │ │ ├── hashes.go
│ │ │ ├── hashes_generic.go
│ │ │ ├── keccakf.go
│ │ │ ├── keccakf_amd64.go
│ │ │ ├── keccakf_amd64.s
│ │ │ ├── register.go
│ │ │ ├── sha3.go
│ │ │ ├── sha3_s390x.go
│ │ │ ├── sha3_s390x.s
│ │ │ ├── sha3_test.go
│ │ │ ├── shake.go
│ │ │ ├── shake_generic.go
│ │ │ ├── testdata
│ │ │ │ └── keccakKats.json.deflate
│ │ │ ├── xor.go
│ │ │ ├── xor_generic.go
│ │ │ └── xor_unaligned.go
│ │ │ ├── ssh
│ │ │ ├── agent
│ │ │ │ ├── client.go
│ │ │ │ ├── client_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── forward.go
│ │ │ │ ├── keyring.go
│ │ │ │ ├── keyring_test.go
│ │ │ │ ├── server.go
│ │ │ │ ├── server_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── benchmark_test.go
│ │ │ ├── buffer.go
│ │ │ ├── buffer_test.go
│ │ │ ├── certs.go
│ │ │ ├── certs_test.go
│ │ │ ├── channel.go
│ │ │ ├── cipher.go
│ │ │ ├── cipher_test.go
│ │ │ ├── client.go
│ │ │ ├── client_auth.go
│ │ │ ├── client_auth_test.go
│ │ │ ├── client_test.go
│ │ │ ├── common.go
│ │ │ ├── connection.go
│ │ │ ├── doc.go
│ │ │ ├── example_test.go
│ │ │ ├── handshake.go
│ │ │ ├── handshake_test.go
│ │ │ ├── kex.go
│ │ │ ├── kex_test.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── knownhosts
│ │ │ │ ├── knownhosts.go
│ │ │ │ └── knownhosts_test.go
│ │ │ ├── mac.go
│ │ │ ├── mempipe_test.go
│ │ │ ├── messages.go
│ │ │ ├── messages_test.go
│ │ │ ├── mux.go
│ │ │ ├── mux_test.go
│ │ │ ├── server.go
│ │ │ ├── session.go
│ │ │ ├── session_test.go
│ │ │ ├── streamlocal.go
│ │ │ ├── tcpip.go
│ │ │ ├── tcpip_test.go
│ │ │ ├── terminal
│ │ │ │ ├── terminal.go
│ │ │ │ ├── terminal_test.go
│ │ │ │ ├── util.go
│ │ │ │ ├── util_bsd.go
│ │ │ │ ├── util_linux.go
│ │ │ │ ├── util_plan9.go
│ │ │ │ ├── util_solaris.go
│ │ │ │ └── util_windows.go
│ │ │ ├── test
│ │ │ │ ├── agent_unix_test.go
│ │ │ │ ├── banner_test.go
│ │ │ │ ├── cert_test.go
│ │ │ │ ├── dial_unix_test.go
│ │ │ │ ├── doc.go
│ │ │ │ ├── forward_unix_test.go
│ │ │ │ ├── multi_auth_test.go
│ │ │ │ ├── session_test.go
│ │ │ │ ├── sshd_test_pw.c
│ │ │ │ ├── test_unix_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── testdata
│ │ │ │ ├── doc.go
│ │ │ │ └── keys.go
│ │ │ ├── testdata_test.go
│ │ │ ├── transport.go
│ │ │ └── transport_test.go
│ │ │ ├── tea
│ │ │ ├── cipher.go
│ │ │ └── tea_test.go
│ │ │ ├── twofish
│ │ │ ├── twofish.go
│ │ │ └── twofish_test.go
│ │ │ ├── xtea
│ │ │ ├── block.go
│ │ │ ├── cipher.go
│ │ │ └── xtea_test.go
│ │ │ └── xts
│ │ │ ├── xts.go
│ │ │ └── xts_test.go
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── cli.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_printblockchain.go
│ │ ├── main.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ └── utils.go
├── 03.工作量证明_挖矿的实现
│ ├── 03.工作量证明_挖矿的实现.md
│ ├── golang.org
│ │ └── x
│ │ │ └── crypto
│ │ │ ├── .gitattributes
│ │ │ ├── .gitignore
│ │ │ ├── AUTHORS
│ │ │ ├── CONTRIBUTING.md
│ │ │ ├── CONTRIBUTORS
│ │ │ ├── LICENSE
│ │ │ ├── PATENTS
│ │ │ ├── README.md
│ │ │ ├── acme
│ │ │ ├── acme.go
│ │ │ ├── acme_test.go
│ │ │ ├── autocert
│ │ │ │ ├── autocert.go
│ │ │ │ ├── autocert_test.go
│ │ │ │ ├── cache.go
│ │ │ │ ├── cache_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── internal
│ │ │ │ │ └── acmetest
│ │ │ │ │ │ └── ca.go
│ │ │ │ ├── listener.go
│ │ │ │ ├── renewal.go
│ │ │ │ └── renewal_test.go
│ │ │ ├── http.go
│ │ │ ├── http_test.go
│ │ │ ├── jws.go
│ │ │ ├── jws_test.go
│ │ │ ├── types.go
│ │ │ └── types_test.go
│ │ │ ├── argon2
│ │ │ ├── argon2.go
│ │ │ ├── argon2_test.go
│ │ │ ├── blake2b.go
│ │ │ ├── blamka_amd64.go
│ │ │ ├── blamka_amd64.s
│ │ │ ├── blamka_generic.go
│ │ │ └── blamka_ref.go
│ │ │ ├── bcrypt
│ │ │ ├── base64.go
│ │ │ ├── bcrypt.go
│ │ │ └── bcrypt_test.go
│ │ │ ├── blake2b
│ │ │ ├── blake2b.go
│ │ │ ├── blake2bAVX2_amd64.go
│ │ │ ├── blake2bAVX2_amd64.s
│ │ │ ├── blake2b_amd64.go
│ │ │ ├── blake2b_amd64.s
│ │ │ ├── blake2b_generic.go
│ │ │ ├── blake2b_ref.go
│ │ │ ├── blake2b_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blake2s
│ │ │ ├── blake2s.go
│ │ │ ├── blake2s_386.go
│ │ │ ├── blake2s_386.s
│ │ │ ├── blake2s_amd64.go
│ │ │ ├── blake2s_amd64.s
│ │ │ ├── blake2s_generic.go
│ │ │ ├── blake2s_ref.go
│ │ │ ├── blake2s_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blowfish
│ │ │ ├── block.go
│ │ │ ├── blowfish_test.go
│ │ │ ├── cipher.go
│ │ │ └── const.go
│ │ │ ├── bn256
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ │ │ ├── cast5
│ │ │ ├── cast5.go
│ │ │ └── cast5_test.go
│ │ │ ├── chacha20poly1305
│ │ │ ├── chacha20poly1305.go
│ │ │ ├── chacha20poly1305_amd64.go
│ │ │ ├── chacha20poly1305_amd64.s
│ │ │ ├── chacha20poly1305_generic.go
│ │ │ ├── chacha20poly1305_noasm.go
│ │ │ ├── chacha20poly1305_test.go
│ │ │ ├── chacha20poly1305_vectors_test.go
│ │ │ └── xchacha20poly1305.go
│ │ │ ├── codereview.cfg
│ │ │ ├── cryptobyte
│ │ │ ├── asn1.go
│ │ │ ├── asn1
│ │ │ │ └── asn1.go
│ │ │ ├── asn1_test.go
│ │ │ ├── builder.go
│ │ │ ├── cryptobyte_test.go
│ │ │ ├── example_test.go
│ │ │ └── string.go
│ │ │ ├── curve25519
│ │ │ ├── const_amd64.h
│ │ │ ├── const_amd64.s
│ │ │ ├── cswap_amd64.s
│ │ │ ├── curve25519.go
│ │ │ ├── curve25519_test.go
│ │ │ ├── doc.go
│ │ │ ├── freeze_amd64.s
│ │ │ ├── ladderstep_amd64.s
│ │ │ ├── mont25519_amd64.go
│ │ │ ├── mul_amd64.s
│ │ │ └── square_amd64.s
│ │ │ ├── ed25519
│ │ │ ├── ed25519.go
│ │ │ ├── ed25519_test.go
│ │ │ ├── internal
│ │ │ │ └── edwards25519
│ │ │ │ │ ├── const.go
│ │ │ │ │ └── edwards25519.go
│ │ │ └── testdata
│ │ │ │ └── sign.input.gz
│ │ │ ├── hkdf
│ │ │ ├── example_test.go
│ │ │ ├── hkdf.go
│ │ │ └── hkdf_test.go
│ │ │ ├── internal
│ │ │ ├── chacha20
│ │ │ │ ├── chacha_generic.go
│ │ │ │ ├── chacha_noasm.go
│ │ │ │ ├── chacha_s390x.go
│ │ │ │ ├── chacha_s390x.s
│ │ │ │ ├── chacha_test.go
│ │ │ │ ├── vectors_test.go
│ │ │ │ └── xor.go
│ │ │ └── subtle
│ │ │ │ ├── aliasing.go
│ │ │ │ ├── aliasing_appengine.go
│ │ │ │ └── aliasing_test.go
│ │ │ ├── md4
│ │ │ ├── example_test.go
│ │ │ ├── md4.go
│ │ │ ├── md4_test.go
│ │ │ └── md4block.go
│ │ │ ├── nacl
│ │ │ ├── auth
│ │ │ │ ├── auth.go
│ │ │ │ ├── auth_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── box
│ │ │ │ ├── box.go
│ │ │ │ ├── box_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── secretbox
│ │ │ │ ├── example_test.go
│ │ │ │ ├── secretbox.go
│ │ │ │ └── secretbox_test.go
│ │ │ └── sign
│ │ │ │ ├── sign.go
│ │ │ │ └── sign_test.go
│ │ │ ├── ocsp
│ │ │ ├── ocsp.go
│ │ │ └── ocsp_test.go
│ │ │ ├── openpgp
│ │ │ ├── armor
│ │ │ │ ├── armor.go
│ │ │ │ ├── armor_test.go
│ │ │ │ └── encode.go
│ │ │ ├── canonical_text.go
│ │ │ ├── canonical_text_test.go
│ │ │ ├── clearsign
│ │ │ │ ├── clearsign.go
│ │ │ │ └── clearsign_test.go
│ │ │ ├── elgamal
│ │ │ │ ├── elgamal.go
│ │ │ │ └── elgamal_test.go
│ │ │ ├── errors
│ │ │ │ └── errors.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── packet
│ │ │ │ ├── compressed.go
│ │ │ │ ├── compressed_test.go
│ │ │ │ ├── config.go
│ │ │ │ ├── encrypted_key.go
│ │ │ │ ├── encrypted_key_test.go
│ │ │ │ ├── literal.go
│ │ │ │ ├── ocfb.go
│ │ │ │ ├── ocfb_test.go
│ │ │ │ ├── one_pass_signature.go
│ │ │ │ ├── opaque.go
│ │ │ │ ├── opaque_test.go
│ │ │ │ ├── packet.go
│ │ │ │ ├── packet_test.go
│ │ │ │ ├── private_key.go
│ │ │ │ ├── private_key_test.go
│ │ │ │ ├── public_key.go
│ │ │ │ ├── public_key_test.go
│ │ │ │ ├── public_key_v3.go
│ │ │ │ ├── public_key_v3_test.go
│ │ │ │ ├── reader.go
│ │ │ │ ├── signature.go
│ │ │ │ ├── signature_test.go
│ │ │ │ ├── signature_v3.go
│ │ │ │ ├── signature_v3_test.go
│ │ │ │ ├── symmetric_key_encrypted.go
│ │ │ │ ├── symmetric_key_encrypted_test.go
│ │ │ │ ├── symmetrically_encrypted.go
│ │ │ │ ├── symmetrically_encrypted_test.go
│ │ │ │ ├── userattribute.go
│ │ │ │ ├── userattribute_test.go
│ │ │ │ ├── userid.go
│ │ │ │ └── userid_test.go
│ │ │ ├── read.go
│ │ │ ├── read_test.go
│ │ │ ├── s2k
│ │ │ │ ├── s2k.go
│ │ │ │ └── s2k_test.go
│ │ │ ├── write.go
│ │ │ └── write_test.go
│ │ │ ├── otr
│ │ │ ├── libotr_test_helper.c
│ │ │ ├── otr.go
│ │ │ ├── otr_test.go
│ │ │ └── smp.go
│ │ │ ├── pbkdf2
│ │ │ ├── pbkdf2.go
│ │ │ └── pbkdf2_test.go
│ │ │ ├── pkcs12
│ │ │ ├── bmp-string.go
│ │ │ ├── bmp-string_test.go
│ │ │ ├── crypto.go
│ │ │ ├── crypto_test.go
│ │ │ ├── errors.go
│ │ │ ├── internal
│ │ │ │ └── rc2
│ │ │ │ │ ├── bench_test.go
│ │ │ │ │ ├── rc2.go
│ │ │ │ │ └── rc2_test.go
│ │ │ ├── mac.go
│ │ │ ├── mac_test.go
│ │ │ ├── pbkdf.go
│ │ │ ├── pbkdf_test.go
│ │ │ ├── pkcs12.go
│ │ │ ├── pkcs12_test.go
│ │ │ └── safebags.go
│ │ │ ├── poly1305
│ │ │ ├── poly1305.go
│ │ │ ├── poly1305_test.go
│ │ │ ├── sum_amd64.go
│ │ │ ├── sum_amd64.s
│ │ │ ├── sum_arm.go
│ │ │ ├── sum_arm.s
│ │ │ ├── sum_noasm.go
│ │ │ ├── sum_ref.go
│ │ │ ├── sum_s390x.go
│ │ │ ├── sum_s390x.s
│ │ │ ├── sum_vmsl_s390x.s
│ │ │ └── vectors_test.go
│ │ │ ├── ripemd160
│ │ │ ├── ripemd160.go
│ │ │ ├── ripemd160_test.go
│ │ │ └── ripemd160block.go
│ │ │ ├── salsa20
│ │ │ ├── salsa
│ │ │ │ ├── hsalsa20.go
│ │ │ │ ├── salsa2020_amd64.s
│ │ │ │ ├── salsa208.go
│ │ │ │ ├── salsa20_amd64.go
│ │ │ │ ├── salsa20_ref.go
│ │ │ │ └── salsa_test.go
│ │ │ ├── salsa20.go
│ │ │ └── salsa20_test.go
│ │ │ ├── scrypt
│ │ │ ├── example_test.go
│ │ │ ├── scrypt.go
│ │ │ └── scrypt_test.go
│ │ │ ├── sha3
│ │ │ ├── doc.go
│ │ │ ├── hashes.go
│ │ │ ├── hashes_generic.go
│ │ │ ├── keccakf.go
│ │ │ ├── keccakf_amd64.go
│ │ │ ├── keccakf_amd64.s
│ │ │ ├── register.go
│ │ │ ├── sha3.go
│ │ │ ├── sha3_s390x.go
│ │ │ ├── sha3_s390x.s
│ │ │ ├── sha3_test.go
│ │ │ ├── shake.go
│ │ │ ├── shake_generic.go
│ │ │ ├── testdata
│ │ │ │ └── keccakKats.json.deflate
│ │ │ ├── xor.go
│ │ │ ├── xor_generic.go
│ │ │ └── xor_unaligned.go
│ │ │ ├── ssh
│ │ │ ├── agent
│ │ │ │ ├── client.go
│ │ │ │ ├── client_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── forward.go
│ │ │ │ ├── keyring.go
│ │ │ │ ├── keyring_test.go
│ │ │ │ ├── server.go
│ │ │ │ ├── server_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── benchmark_test.go
│ │ │ ├── buffer.go
│ │ │ ├── buffer_test.go
│ │ │ ├── certs.go
│ │ │ ├── certs_test.go
│ │ │ ├── channel.go
│ │ │ ├── cipher.go
│ │ │ ├── cipher_test.go
│ │ │ ├── client.go
│ │ │ ├── client_auth.go
│ │ │ ├── client_auth_test.go
│ │ │ ├── client_test.go
│ │ │ ├── common.go
│ │ │ ├── connection.go
│ │ │ ├── doc.go
│ │ │ ├── example_test.go
│ │ │ ├── handshake.go
│ │ │ ├── handshake_test.go
│ │ │ ├── kex.go
│ │ │ ├── kex_test.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── knownhosts
│ │ │ │ ├── knownhosts.go
│ │ │ │ └── knownhosts_test.go
│ │ │ ├── mac.go
│ │ │ ├── mempipe_test.go
│ │ │ ├── messages.go
│ │ │ ├── messages_test.go
│ │ │ ├── mux.go
│ │ │ ├── mux_test.go
│ │ │ ├── server.go
│ │ │ ├── session.go
│ │ │ ├── session_test.go
│ │ │ ├── streamlocal.go
│ │ │ ├── tcpip.go
│ │ │ ├── tcpip_test.go
│ │ │ ├── terminal
│ │ │ │ ├── terminal.go
│ │ │ │ ├── terminal_test.go
│ │ │ │ ├── util.go
│ │ │ │ ├── util_bsd.go
│ │ │ │ ├── util_linux.go
│ │ │ │ ├── util_plan9.go
│ │ │ │ ├── util_solaris.go
│ │ │ │ └── util_windows.go
│ │ │ ├── test
│ │ │ │ ├── agent_unix_test.go
│ │ │ │ ├── banner_test.go
│ │ │ │ ├── cert_test.go
│ │ │ │ ├── dial_unix_test.go
│ │ │ │ ├── doc.go
│ │ │ │ ├── forward_unix_test.go
│ │ │ │ ├── multi_auth_test.go
│ │ │ │ ├── session_test.go
│ │ │ │ ├── sshd_test_pw.c
│ │ │ │ ├── test_unix_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── testdata
│ │ │ │ ├── doc.go
│ │ │ │ └── keys.go
│ │ │ ├── testdata_test.go
│ │ │ ├── transport.go
│ │ │ └── transport_test.go
│ │ │ ├── tea
│ │ │ ├── cipher.go
│ │ │ └── tea_test.go
│ │ │ ├── twofish
│ │ │ ├── twofish.go
│ │ │ └── twofish_test.go
│ │ │ ├── xtea
│ │ │ ├── block.go
│ │ │ ├── cipher.go
│ │ │ └── xtea_test.go
│ │ │ └── xts
│ │ │ ├── xts.go
│ │ │ └── xts_test.go
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── cli.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_printblockchain.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ └── utils.go
├── 04.区块链数据结构的实现-2
│ ├── 04.区块链数据结构的实现.md
│ ├── blotdbDemo
│ │ ├── main.go
│ │ └── student.go
│ ├── golang.org
│ │ └── x
│ │ │ └── crypto
│ │ │ ├── .gitattributes
│ │ │ ├── .gitignore
│ │ │ ├── AUTHORS
│ │ │ ├── CONTRIBUTING.md
│ │ │ ├── CONTRIBUTORS
│ │ │ ├── LICENSE
│ │ │ ├── PATENTS
│ │ │ ├── README.md
│ │ │ ├── acme
│ │ │ ├── acme.go
│ │ │ ├── acme_test.go
│ │ │ ├── autocert
│ │ │ │ ├── autocert.go
│ │ │ │ ├── autocert_test.go
│ │ │ │ ├── cache.go
│ │ │ │ ├── cache_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── internal
│ │ │ │ │ └── acmetest
│ │ │ │ │ │ └── ca.go
│ │ │ │ ├── listener.go
│ │ │ │ ├── renewal.go
│ │ │ │ └── renewal_test.go
│ │ │ ├── http.go
│ │ │ ├── http_test.go
│ │ │ ├── jws.go
│ │ │ ├── jws_test.go
│ │ │ ├── types.go
│ │ │ └── types_test.go
│ │ │ ├── argon2
│ │ │ ├── argon2.go
│ │ │ ├── argon2_test.go
│ │ │ ├── blake2b.go
│ │ │ ├── blamka_amd64.go
│ │ │ ├── blamka_amd64.s
│ │ │ ├── blamka_generic.go
│ │ │ └── blamka_ref.go
│ │ │ ├── bcrypt
│ │ │ ├── base64.go
│ │ │ ├── bcrypt.go
│ │ │ └── bcrypt_test.go
│ │ │ ├── blake2b
│ │ │ ├── blake2b.go
│ │ │ ├── blake2bAVX2_amd64.go
│ │ │ ├── blake2bAVX2_amd64.s
│ │ │ ├── blake2b_amd64.go
│ │ │ ├── blake2b_amd64.s
│ │ │ ├── blake2b_generic.go
│ │ │ ├── blake2b_ref.go
│ │ │ ├── blake2b_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blake2s
│ │ │ ├── blake2s.go
│ │ │ ├── blake2s_386.go
│ │ │ ├── blake2s_386.s
│ │ │ ├── blake2s_amd64.go
│ │ │ ├── blake2s_amd64.s
│ │ │ ├── blake2s_generic.go
│ │ │ ├── blake2s_ref.go
│ │ │ ├── blake2s_test.go
│ │ │ ├── blake2x.go
│ │ │ └── register.go
│ │ │ ├── blowfish
│ │ │ ├── block.go
│ │ │ ├── blowfish_test.go
│ │ │ ├── cipher.go
│ │ │ └── const.go
│ │ │ ├── bn256
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ │ │ ├── cast5
│ │ │ ├── cast5.go
│ │ │ └── cast5_test.go
│ │ │ ├── chacha20poly1305
│ │ │ ├── chacha20poly1305.go
│ │ │ ├── chacha20poly1305_amd64.go
│ │ │ ├── chacha20poly1305_amd64.s
│ │ │ ├── chacha20poly1305_generic.go
│ │ │ ├── chacha20poly1305_noasm.go
│ │ │ ├── chacha20poly1305_test.go
│ │ │ ├── chacha20poly1305_vectors_test.go
│ │ │ └── xchacha20poly1305.go
│ │ │ ├── codereview.cfg
│ │ │ ├── cryptobyte
│ │ │ ├── asn1.go
│ │ │ ├── asn1
│ │ │ │ └── asn1.go
│ │ │ ├── asn1_test.go
│ │ │ ├── builder.go
│ │ │ ├── cryptobyte_test.go
│ │ │ ├── example_test.go
│ │ │ └── string.go
│ │ │ ├── curve25519
│ │ │ ├── const_amd64.h
│ │ │ ├── const_amd64.s
│ │ │ ├── cswap_amd64.s
│ │ │ ├── curve25519.go
│ │ │ ├── curve25519_test.go
│ │ │ ├── doc.go
│ │ │ ├── freeze_amd64.s
│ │ │ ├── ladderstep_amd64.s
│ │ │ ├── mont25519_amd64.go
│ │ │ ├── mul_amd64.s
│ │ │ └── square_amd64.s
│ │ │ ├── ed25519
│ │ │ ├── ed25519.go
│ │ │ ├── ed25519_test.go
│ │ │ ├── internal
│ │ │ │ └── edwards25519
│ │ │ │ │ ├── const.go
│ │ │ │ │ └── edwards25519.go
│ │ │ └── testdata
│ │ │ │ └── sign.input.gz
│ │ │ ├── hkdf
│ │ │ ├── example_test.go
│ │ │ ├── hkdf.go
│ │ │ └── hkdf_test.go
│ │ │ ├── internal
│ │ │ ├── chacha20
│ │ │ │ ├── chacha_generic.go
│ │ │ │ ├── chacha_noasm.go
│ │ │ │ ├── chacha_s390x.go
│ │ │ │ ├── chacha_s390x.s
│ │ │ │ ├── chacha_test.go
│ │ │ │ ├── vectors_test.go
│ │ │ │ └── xor.go
│ │ │ └── subtle
│ │ │ │ ├── aliasing.go
│ │ │ │ ├── aliasing_appengine.go
│ │ │ │ └── aliasing_test.go
│ │ │ ├── md4
│ │ │ ├── example_test.go
│ │ │ ├── md4.go
│ │ │ ├── md4_test.go
│ │ │ └── md4block.go
│ │ │ ├── nacl
│ │ │ ├── auth
│ │ │ │ ├── auth.go
│ │ │ │ ├── auth_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── box
│ │ │ │ ├── box.go
│ │ │ │ ├── box_test.go
│ │ │ │ └── example_test.go
│ │ │ ├── secretbox
│ │ │ │ ├── example_test.go
│ │ │ │ ├── secretbox.go
│ │ │ │ └── secretbox_test.go
│ │ │ └── sign
│ │ │ │ ├── sign.go
│ │ │ │ └── sign_test.go
│ │ │ ├── ocsp
│ │ │ ├── ocsp.go
│ │ │ └── ocsp_test.go
│ │ │ ├── openpgp
│ │ │ ├── armor
│ │ │ │ ├── armor.go
│ │ │ │ ├── armor_test.go
│ │ │ │ └── encode.go
│ │ │ ├── canonical_text.go
│ │ │ ├── canonical_text_test.go
│ │ │ ├── clearsign
│ │ │ │ ├── clearsign.go
│ │ │ │ └── clearsign_test.go
│ │ │ ├── elgamal
│ │ │ │ ├── elgamal.go
│ │ │ │ └── elgamal_test.go
│ │ │ ├── errors
│ │ │ │ └── errors.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── packet
│ │ │ │ ├── compressed.go
│ │ │ │ ├── compressed_test.go
│ │ │ │ ├── config.go
│ │ │ │ ├── encrypted_key.go
│ │ │ │ ├── encrypted_key_test.go
│ │ │ │ ├── literal.go
│ │ │ │ ├── ocfb.go
│ │ │ │ ├── ocfb_test.go
│ │ │ │ ├── one_pass_signature.go
│ │ │ │ ├── opaque.go
│ │ │ │ ├── opaque_test.go
│ │ │ │ ├── packet.go
│ │ │ │ ├── packet_test.go
│ │ │ │ ├── private_key.go
│ │ │ │ ├── private_key_test.go
│ │ │ │ ├── public_key.go
│ │ │ │ ├── public_key_test.go
│ │ │ │ ├── public_key_v3.go
│ │ │ │ ├── public_key_v3_test.go
│ │ │ │ ├── reader.go
│ │ │ │ ├── signature.go
│ │ │ │ ├── signature_test.go
│ │ │ │ ├── signature_v3.go
│ │ │ │ ├── signature_v3_test.go
│ │ │ │ ├── symmetric_key_encrypted.go
│ │ │ │ ├── symmetric_key_encrypted_test.go
│ │ │ │ ├── symmetrically_encrypted.go
│ │ │ │ ├── symmetrically_encrypted_test.go
│ │ │ │ ├── userattribute.go
│ │ │ │ ├── userattribute_test.go
│ │ │ │ ├── userid.go
│ │ │ │ └── userid_test.go
│ │ │ ├── read.go
│ │ │ ├── read_test.go
│ │ │ ├── s2k
│ │ │ │ ├── s2k.go
│ │ │ │ └── s2k_test.go
│ │ │ ├── write.go
│ │ │ └── write_test.go
│ │ │ ├── otr
│ │ │ ├── libotr_test_helper.c
│ │ │ ├── otr.go
│ │ │ ├── otr_test.go
│ │ │ └── smp.go
│ │ │ ├── pbkdf2
│ │ │ ├── pbkdf2.go
│ │ │ └── pbkdf2_test.go
│ │ │ ├── pkcs12
│ │ │ ├── bmp-string.go
│ │ │ ├── bmp-string_test.go
│ │ │ ├── crypto.go
│ │ │ ├── crypto_test.go
│ │ │ ├── errors.go
│ │ │ ├── internal
│ │ │ │ └── rc2
│ │ │ │ │ ├── bench_test.go
│ │ │ │ │ ├── rc2.go
│ │ │ │ │ └── rc2_test.go
│ │ │ ├── mac.go
│ │ │ ├── mac_test.go
│ │ │ ├── pbkdf.go
│ │ │ ├── pbkdf_test.go
│ │ │ ├── pkcs12.go
│ │ │ ├── pkcs12_test.go
│ │ │ └── safebags.go
│ │ │ ├── poly1305
│ │ │ ├── poly1305.go
│ │ │ ├── poly1305_test.go
│ │ │ ├── sum_amd64.go
│ │ │ ├── sum_amd64.s
│ │ │ ├── sum_arm.go
│ │ │ ├── sum_arm.s
│ │ │ ├── sum_noasm.go
│ │ │ ├── sum_ref.go
│ │ │ ├── sum_s390x.go
│ │ │ ├── sum_s390x.s
│ │ │ ├── sum_vmsl_s390x.s
│ │ │ └── vectors_test.go
│ │ │ ├── ripemd160
│ │ │ ├── ripemd160.go
│ │ │ ├── ripemd160_test.go
│ │ │ └── ripemd160block.go
│ │ │ ├── salsa20
│ │ │ ├── salsa
│ │ │ │ ├── hsalsa20.go
│ │ │ │ ├── salsa2020_amd64.s
│ │ │ │ ├── salsa208.go
│ │ │ │ ├── salsa20_amd64.go
│ │ │ │ ├── salsa20_ref.go
│ │ │ │ └── salsa_test.go
│ │ │ ├── salsa20.go
│ │ │ └── salsa20_test.go
│ │ │ ├── scrypt
│ │ │ ├── example_test.go
│ │ │ ├── scrypt.go
│ │ │ └── scrypt_test.go
│ │ │ ├── sha3
│ │ │ ├── doc.go
│ │ │ ├── hashes.go
│ │ │ ├── hashes_generic.go
│ │ │ ├── keccakf.go
│ │ │ ├── keccakf_amd64.go
│ │ │ ├── keccakf_amd64.s
│ │ │ ├── register.go
│ │ │ ├── sha3.go
│ │ │ ├── sha3_s390x.go
│ │ │ ├── sha3_s390x.s
│ │ │ ├── sha3_test.go
│ │ │ ├── shake.go
│ │ │ ├── shake_generic.go
│ │ │ ├── testdata
│ │ │ │ └── keccakKats.json.deflate
│ │ │ ├── xor.go
│ │ │ ├── xor_generic.go
│ │ │ └── xor_unaligned.go
│ │ │ ├── ssh
│ │ │ ├── agent
│ │ │ │ ├── client.go
│ │ │ │ ├── client_test.go
│ │ │ │ ├── example_test.go
│ │ │ │ ├── forward.go
│ │ │ │ ├── keyring.go
│ │ │ │ ├── keyring_test.go
│ │ │ │ ├── server.go
│ │ │ │ ├── server_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── benchmark_test.go
│ │ │ ├── buffer.go
│ │ │ ├── buffer_test.go
│ │ │ ├── certs.go
│ │ │ ├── certs_test.go
│ │ │ ├── channel.go
│ │ │ ├── cipher.go
│ │ │ ├── cipher_test.go
│ │ │ ├── client.go
│ │ │ ├── client_auth.go
│ │ │ ├── client_auth_test.go
│ │ │ ├── client_test.go
│ │ │ ├── common.go
│ │ │ ├── connection.go
│ │ │ ├── doc.go
│ │ │ ├── example_test.go
│ │ │ ├── handshake.go
│ │ │ ├── handshake_test.go
│ │ │ ├── kex.go
│ │ │ ├── kex_test.go
│ │ │ ├── keys.go
│ │ │ ├── keys_test.go
│ │ │ ├── knownhosts
│ │ │ │ ├── knownhosts.go
│ │ │ │ └── knownhosts_test.go
│ │ │ ├── mac.go
│ │ │ ├── mempipe_test.go
│ │ │ ├── messages.go
│ │ │ ├── messages_test.go
│ │ │ ├── mux.go
│ │ │ ├── mux_test.go
│ │ │ ├── server.go
│ │ │ ├── session.go
│ │ │ ├── session_test.go
│ │ │ ├── streamlocal.go
│ │ │ ├── tcpip.go
│ │ │ ├── tcpip_test.go
│ │ │ ├── terminal
│ │ │ │ ├── terminal.go
│ │ │ │ ├── terminal_test.go
│ │ │ │ ├── util.go
│ │ │ │ ├── util_bsd.go
│ │ │ │ ├── util_linux.go
│ │ │ │ ├── util_plan9.go
│ │ │ │ ├── util_solaris.go
│ │ │ │ └── util_windows.go
│ │ │ ├── test
│ │ │ │ ├── agent_unix_test.go
│ │ │ │ ├── banner_test.go
│ │ │ │ ├── cert_test.go
│ │ │ │ ├── dial_unix_test.go
│ │ │ │ ├── doc.go
│ │ │ │ ├── forward_unix_test.go
│ │ │ │ ├── multi_auth_test.go
│ │ │ │ ├── session_test.go
│ │ │ │ ├── sshd_test_pw.c
│ │ │ │ ├── test_unix_test.go
│ │ │ │ └── testdata_test.go
│ │ │ ├── testdata
│ │ │ │ ├── doc.go
│ │ │ │ └── keys.go
│ │ │ ├── testdata_test.go
│ │ │ ├── transport.go
│ │ │ └── transport_test.go
│ │ │ ├── tea
│ │ │ ├── cipher.go
│ │ │ └── tea_test.go
│ │ │ ├── twofish
│ │ │ ├── twofish.go
│ │ │ └── twofish_test.go
│ │ │ ├── xtea
│ │ │ ├── block.go
│ │ │ ├── cipher.go
│ │ │ └── xtea_test.go
│ │ │ └── xts
│ │ │ ├── xts.go
│ │ │ └── xts_test.go
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_mine.go
│ │ ├── cli_printblockchain.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ └── utils.go
├── 05.实现UTXO交易
│ ├── 05.实现UTXO交易.md
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_printblockchain.go
│ │ ├── cli_send.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── transaction_outputs.go
│ │ ├── utils.go
│ │ └── utxo_set.go
├── 06.MerkleTree-梅克尔树
│ ├── 06.MerkleTree-梅克尔树.md
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── blc
│ │ ├── block.go
│ │ ├── blockchain.db
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_printblockchain.go
│ │ ├── cli_send.go
│ │ ├── main.go
│ │ ├── merkle_tree.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── transaction_outputs.go
│ │ ├── utils.go
│ │ ├── utxo_set.go
│ │ └── wallets.dat
├── 07.数字签名的实现
│ ├── 07.数字签名的实现.md
│ └── src
│ │ ├── Wallet.go
│ │ ├── Wallets.go
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddresses.go
│ │ ├── cli_printblockchain.go
│ │ ├── cli_send.go
│ │ ├── main.go
│ │ ├── merkle_tree.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── transaction_outputs.go
│ │ ├── utils.go
│ │ └── utxo_set.go
└── README.md
├── 以太坊
├── 01.geth的安装步骤.md
├── 01.以太坊综述.pptx
├── 02.使用geth来搭建私有链.md
├── DAICO.doc
├── Ebay项目
│ ├── Ebay.md
│ ├── README.md
│ └── images
│ │ ├── add-product-flow.png
│ │ ├── centralized-vs-ipfs.png
│ │ ├── ebay-dapp-architecture.png
│ │ ├── ebay-dapp-frontend-1.png
│ │ ├── ebay-list-item.png
│ │ └── list-product.png
├── Truffle构建简单投票系统.doc
├── Ubuntu安装区块链必备工具.md
├── Web3.js.pptx
├── 众筹DAPP
│ └── src
│ │ ├── build
│ │ ├── Project.json
│ │ ├── ProjectList.json
│ │ ├── SafeMath.json
│ │ └── address.json
│ │ ├── component
│ │ ├── accounts.js
│ │ ├── app.js
│ │ ├── createProject.js
│ │ ├── details.js
│ │ └── projects.js
│ │ ├── index.js
│ │ ├── libs
│ │ ├── project.js
│ │ ├── projectList.js
│ │ └── web3.js
│ │ └── serviceWorker.js
├── 基于Token投票系统的Dapp.doc
├── 基于Token的投票
│ └── src
│ │ ├── VoteToken.sol
│ │ └── VoteTokenApp.js
├── 基于token投票的合约.md
└── 简单投票系统的Dapp.doc
└── 比特币权威教材
├── Golang实现比特币
├── 01-基本原型
│ ├── basic-prototype.md
│ └── src
│ │ ├── Makefile
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ └── main.go
├── 02-工作量证明
│ ├── proof-of-work.md
│ └── src
│ │ ├── Makefile
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ └── utils.go
├── 03-持久化和CLI
│ ├── persistence-and-cli.md
│ └── src
│ │ ├── .idea
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ ├── src.iml
│ │ ├── vcs.xml
│ │ └── workspace.xml
│ │ ├── Makefile
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── cli.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ └── utils.go
├── 04-交易(1)实现UTXO机制
│ ├── img
│ │ └── blockchain-info-tx.png
│ ├── src
│ │ ├── Makefile
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── cli.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ └── utils.go
│ └── transactions-1.md
├── 05-比特币地址和数字签名
│ ├── address.md
│ └── src
│ │ ├── Makefile
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddress.go
│ │ ├── cli_printchain.go
│ │ ├── cli_send.go
│ │ ├── main.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── utils.go
│ │ ├── wallet.go
│ │ └── wallets.go
├── 06-交易(2)优化交易和默克尔树
│ ├── src
│ │ ├── Makefile
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddress.go
│ │ ├── cli_printchain.go
│ │ ├── cli_reindexutxo.go
│ │ ├── cli_send.go
│ │ ├── main.go
│ │ ├── merkle_tree.go
│ │ ├── merkle_tree_test.go
│ │ ├── proofofwork.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── utils.go
│ │ ├── utxo_set.go
│ │ ├── wallet.go
│ │ └── wallets.go
│ └── transactions-2.md
├── 07-网络
│ ├── network.md
│ └── src
│ │ ├── Makefile
│ │ ├── base58.go
│ │ ├── block.go
│ │ ├── blockchain.go
│ │ ├── blockchain_iterator.go
│ │ ├── cli.go
│ │ ├── cli_createblockchain.go
│ │ ├── cli_createwallet.go
│ │ ├── cli_getbalance.go
│ │ ├── cli_listaddress.go
│ │ ├── cli_printchain.go
│ │ ├── cli_reindexutxo.go
│ │ ├── cli_send.go
│ │ ├── cli_startnode.go
│ │ ├── main.go
│ │ ├── merkle_tree.go
│ │ ├── merkle_tree_test.go
│ │ ├── proofofwork.go
│ │ ├── server.go
│ │ ├── transaction.go
│ │ ├── transaction_input.go
│ │ ├── transaction_output.go
│ │ ├── utils.go
│ │ ├── utxo_set.go
│ │ ├── wallet.go
│ │ └── wallets.go
└── 最终版代码
│ ├── Makefile
│ ├── base58.go
│ ├── base58_test.go
│ ├── block.go
│ ├── blockchain.go
│ ├── blockchain_iterator.go
│ ├── cli.go
│ ├── cli_createblockchain.go
│ ├── cli_createwallet.go
│ ├── cli_getbalance.go
│ ├── cli_listaddress.go
│ ├── cli_printchain.go
│ ├── cli_reindexutxo.go
│ ├── cli_send.go
│ ├── cli_startnode.go
│ ├── main.go
│ ├── merkle_tree.go
│ ├── merkle_tree_test.go
│ ├── proofofwork.go
│ ├── server.go
│ ├── transaction.go
│ ├── transaction_input.go
│ ├── transaction_output.go
│ ├── utils.go
│ ├── utxo_set.go
│ ├── wallet.go
│ └── wallets.go
└── 精通比特币
├── code
├── addr.cpp
├── bip-table.py
├── ec-math.py
├── extract-from-pk-script.go
├── get-utxo.py
├── hash_example.py
├── key-to-address-ecc-example.py
├── max_money.py
├── merkle.cpp
├── p2wpkh.js
├── pay-to-addr-script.go
├── proof-of-work-example.py
├── pycoin_example.py
├── rpc_block.py
├── rpc_example.py
├── rpc_transaction.py
├── satoshi-words.cpp
├── select-utxo.py
├── vanity-miner.cpp
└── websocket-example.go
├── images
├── kuozhan.png
└── kuozhan1.png
├── 第一章-介绍.md
├── 第七章-高级交易和脚本.md
├── 第三章-比特币核心.md
├── 第九章-区块链.md
├── 第二章-比特币原理.md
├── 第五章-钱包.md
├── 第八章-比特币网络.md
├── 第六章-交易.md
├── 第十一章-比特币安全.md
├── 第十章-挖矿和共识.md
└── 第四章-密钥和地址.md
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/.gitattributes:
--------------------------------------------------------------------------------
1 | # Treat all files in this repo as binary, with no git magic updating
2 | # line endings. Windows users contributing to Go will need to use a
3 | # modern version of git and editors capable of LF line endings.
4 | #
5 | # We'll prevent accidental CRLF line endings from entering the repo
6 | # via the git-review gofmt checks.
7 | #
8 | # See golang.org/issue/9281
9 |
10 | * -text
11 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .hgignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at https://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 | ## Filing issues
8 |
9 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
10 |
11 | 1. What version of Go are you using (`go version`)?
12 | 2. What operating system and processor architecture are you using?
13 | 3. What did you do?
14 | 4. What did you expect to see?
15 | 5. What did you see instead?
16 |
17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
19 |
20 | ## Contributing code
21 |
22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23 | before sending patches.
24 |
25 | Unless otherwise noted, the Go source files are distributed under
26 | the BSD-style license found in the LICENSE file.
27 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at https://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/README.md:
--------------------------------------------------------------------------------
1 | # Go Cryptography
2 |
3 | This repository holds supplementary Go cryptography libraries.
4 |
5 | ## Download/Install
6 |
7 | The easiest way to install is to run `go get -u golang.org/x/crypto/...`. You
8 | can also manually git clone the repository to `$GOPATH/src/golang.org/x/crypto`.
9 |
10 | ## Report Issues / Send Patches
11 |
12 | This repository uses Gerrit for code changes. To learn how to submit changes to
13 | this repository, see https://golang.org/doc/contribute.html.
14 |
15 | The main issue tracker for the crypto repository is located at
16 | https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the
17 | subject line, so it is easy to find.
18 |
19 | Note that contributions to the cryptography package receive additional scrutiny
20 | due to their sensitive nature. Patches may take longer than normal to receive
21 | feedback.
22 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/acme/autocert/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package autocert_test
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "net/http"
11 |
12 | "golang.org/x/crypto/acme/autocert"
13 | )
14 |
15 | func ExampleNewListener() {
16 | mux := http.NewServeMux()
17 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
19 | })
20 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
21 | }
22 |
23 | func ExampleManager() {
24 | m := &autocert.Manager{
25 | Cache: autocert.DirCache("secret-dir"),
26 | Prompt: autocert.AcceptTOS,
27 | HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
28 | }
29 | s := &http.Server{
30 | Addr: ":https",
31 | TLSConfig: m.TLSConfig(),
32 | }
33 | s.ListenAndServeTLS("", "")
34 | }
35 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/argon2/blamka_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package argon2
8 |
9 | func processBlock(out, in1, in2 *block) {
10 | processBlockGeneric(out, in1, in2, false)
11 | }
12 |
13 | func processBlockXOR(out, in1, in2 *block) {
14 | processBlockGeneric(out, in1, in2, true)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/bcrypt/base64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bcrypt
6 |
7 | import "encoding/base64"
8 |
9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
10 |
11 | var bcEncoding = base64.NewEncoding(alphabet)
12 |
13 | func base64Encode(src []byte) []byte {
14 | n := bcEncoding.EncodedLen(len(src))
15 | dst := make([]byte, n)
16 | bcEncoding.Encode(dst, src)
17 | for dst[n-1] == '=' {
18 | n--
19 | }
20 | return dst[:n]
21 | }
22 |
23 | func base64Decode(src []byte) ([]byte, error) {
24 | numOfEquals := 4 - (len(src) % 4)
25 | for i := 0; i < numOfEquals; i++ {
26 | src = append(src, '=')
27 | }
28 |
29 | dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 | n, err := bcEncoding.Decode(dst, src)
31 | if err != nil {
32 | return nil, err
33 | }
34 | return dst[:n], nil
35 | }
36 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2b/blake2b_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.7,amd64,!gccgo,!appengine
6 |
7 | package blake2b
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | func init() {
12 | useSSE4 = cpu.X86.HasSSE41
13 | }
14 |
15 | //go:noescape
16 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
17 |
18 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
19 | if useSSE4 {
20 | hashBlocksSSE4(h, c, flag, blocks)
21 | } else {
22 | hashBlocksGeneric(h, c, flag, blocks)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2b/blake2b_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package blake2b
8 |
9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
10 | hashBlocksGeneric(h, c, flag, blocks)
11 | }
12 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2b
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 | newHash384 := func() hash.Hash {
20 | h, _ := New384(nil)
21 | return h
22 | }
23 |
24 | newHash512 := func() hash.Hash {
25 | h, _ := New512(nil)
26 | return h
27 | }
28 |
29 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
30 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
31 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2s/blake2s_386.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build 386,!gccgo,!appengine
6 |
7 | package blake2s
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | var (
12 | useSSE4 = false
13 | useSSSE3 = cpu.X86.HasSSSE3
14 | useSSE2 = cpu.X86.HasSSE2
15 | )
16 |
17 | //go:noescape
18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
19 |
20 | //go:noescape
21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
22 |
23 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
24 | switch {
25 | case useSSSE3:
26 | hashBlocksSSSE3(h, c, flag, blocks)
27 | case useSSE2:
28 | hashBlocksSSE2(h, c, flag, blocks)
29 | default:
30 | hashBlocksGeneric(h, c, flag, blocks)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2s/blake2s_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386 gccgo appengine
6 |
7 | package blake2s
8 |
9 | var (
10 | useSSE4 = false
11 | useSSSE3 = false
12 | useSSE2 = false
13 | )
14 |
15 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
16 | hashBlocksGeneric(h, c, flag, blocks)
17 | }
18 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/blake2s/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2s
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 |
20 | crypto.RegisterHash(crypto.BLAKE2s_256, newHash256)
21 | }
22 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 !go1.7 gccgo appengine
6 |
7 | package chacha20poly1305
8 |
9 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte {
10 | return c.sealGeneric(dst, nonce, plaintext, additionalData)
11 | }
12 |
13 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
14 | return c.openGeneric(dst, nonce, ciphertext, additionalData)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/curve25519/const_amd64.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | #define REDMASK51 0x0007FFFFFFFFFFFF
9 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/curve25519/const_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // These constants cannot be encoded in non-MOVQ immediates.
11 | // We access them directly from memory instead.
12 |
13 | DATA ·_121666_213(SB)/8, $996687872
14 | GLOBL ·_121666_213(SB), 8, $8
15 |
16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA
17 | GLOBL ·_2P0(SB), 8, $8
18 |
19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE
20 | GLOBL ·_2P1234(SB), 8, $8
21 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/curve25519/curve25519_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package curve25519
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 | )
11 |
12 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
13 |
14 | func TestBaseScalarMult(t *testing.T) {
15 | var a, b [32]byte
16 | in := &a
17 | out := &b
18 | a[0] = 1
19 |
20 | for i := 0; i < 200; i++ {
21 | ScalarBaseMult(out, in)
22 | in, out = out, in
23 | }
24 |
25 | result := fmt.Sprintf("%x", in[:])
26 | if result != expectedHex {
27 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
28 | }
29 | }
30 |
31 | func BenchmarkScalarBaseMult(b *testing.B) {
32 | var in, out [32]byte
33 | in[0] = 1
34 |
35 | b.SetBytes(32)
36 | for i := 0; i < b.N; i++ {
37 | ScalarBaseMult(&out, &in)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ed25519/testdata/sign.input.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ed25519/testdata/sign.input.gz
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/internal/chacha20/chacha_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !s390x gccgo appengine
6 |
7 | package chacha20
8 |
9 | const (
10 | bufSize = 64
11 | haveAsm = false
12 | )
13 |
14 | func (*Cipher) xorKeyStreamAsm(dst, src []byte) {
15 | panic("not implemented")
16 | }
17 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/md4/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package md4_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 |
11 | "golang.org/x/crypto/md4"
12 | )
13 |
14 | func ExampleNew() {
15 | h := md4.New()
16 | data := "These pretzels are making me thirsty."
17 | io.WriteString(h, data)
18 | fmt.Printf("%x", h.Sum(nil))
19 | // Output: 48c4e365090b30a32f084c4888deceaa
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/pkcs12/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package pkcs12
6 |
7 | import "errors"
8 |
9 | var (
10 | // ErrDecryption represents a failure to decrypt the input.
11 | ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding")
12 |
13 | // ErrIncorrectPassword is returned when an incorrect password is detected.
14 | // Usually, P12/PFX data is signed to be able to verify the password.
15 | ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect")
16 | )
17 |
18 | // NotImplementedError indicates that the input is not currently supported.
19 | type NotImplementedError string
20 |
21 | func (e NotImplementedError) Error() string {
22 | return "pkcs12: " + string(e)
23 | }
24 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package rc2
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func BenchmarkEncrypt(b *testing.B) {
12 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
13 | b.ResetTimer()
14 | var src [8]byte
15 | for i := 0; i < b.N; i++ {
16 | r.Encrypt(src[:], src[:])
17 | }
18 | }
19 |
20 | func BenchmarkDecrypt(b *testing.B) {
21 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
22 | b.ResetTimer()
23 | var src [8]byte
24 | for i := 0; i < b.N; i++ {
25 | r.Decrypt(src[:], src[:])
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/poly1305/sum_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!gccgo,!appengine
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_amd64.s
10 | //go:noescape
11 | func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305(out, mPtr, uint64(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/poly1305/sum_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build arm,!gccgo,!appengine,!nacl
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_arm.s
10 | //go:noescape
11 | func poly1305_auth_armv6(out *[16]byte, m *byte, mlen uint32, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305_auth_armv6(out, mPtr, uint32(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/poly1305/sum_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build s390x,!go1.11 !arm,!amd64,!s390x gccgo appengine nacl
6 |
7 | package poly1305
8 |
9 | // Sum generates an authenticator for msg using a one-time key and puts the
10 | // 16-byte result into out. Authenticating two different messages with the same
11 | // key allows an attacker to forge messages at will.
12 | func Sum(out *[TagSize]byte, msg []byte, key *[32]byte) {
13 | sumGeneric(out, msg, key)
14 | }
15 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package salsa
8 |
9 | // This function is implemented in salsa2020_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte)
14 |
15 | // XORKeyStream crypts bytes from in to out using the given key and counters.
16 | // In and out must overlap entirely or not at all. Counter
17 | // contains the raw salsa20 counter bytes (both nonce and block counter).
18 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
19 | if len(in) == 0 {
20 | return
21 | }
22 | _ = out[len(in)-1]
23 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0])
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/scrypt/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package scrypt_test
6 |
7 | import (
8 | "encoding/base64"
9 | "fmt"
10 | "log"
11 |
12 | "golang.org/x/crypto/scrypt"
13 | )
14 |
15 | func Example() {
16 | // DO NOT use this salt value; generate your own random salt. 8 bytes is
17 | // a good length.
18 | salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b}
19 |
20 | dk, err := scrypt.Key([]byte("some password"), salt, 1<<15, 8, 1, 32)
21 | if err != nil {
22 | log.Fatal(err)
23 | }
24 | fmt.Println(base64.StdEncoding.EncodeToString(dk))
25 | // Output: lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M=
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/hashes_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | import (
10 | "hash"
11 | )
12 |
13 | // new224Asm returns an assembly implementation of SHA3-224 if available,
14 | // otherwise it returns nil.
15 | func new224Asm() hash.Hash { return nil }
16 |
17 | // new256Asm returns an assembly implementation of SHA3-256 if available,
18 | // otherwise it returns nil.
19 | func new256Asm() hash.Hash { return nil }
20 |
21 | // new384Asm returns an assembly implementation of SHA3-384 if available,
22 | // otherwise it returns nil.
23 | func new384Asm() hash.Hash { return nil }
24 |
25 | // new512Asm returns an assembly implementation of SHA3-512 if available,
26 | // otherwise it returns nil.
27 | func new512Asm() hash.Hash { return nil }
28 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/keccakf_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package sha3
8 |
9 | // This function is implemented in keccakf_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func keccakF1600(a *[25]uint64)
14 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.4
6 |
7 | package sha3
8 |
9 | import (
10 | "crypto"
11 | )
12 |
13 | func init() {
14 | crypto.RegisterHash(crypto.SHA3_224, New224)
15 | crypto.RegisterHash(crypto.SHA3_256, New256)
16 | crypto.RegisterHash(crypto.SHA3_384, New384)
17 | crypto.RegisterHash(crypto.SHA3_512, New512)
18 | }
19 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/shake_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
10 | // otherwise it returns nil.
11 | func newShake128Asm() ShakeHash {
12 | return nil
13 | }
14 |
15 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
16 | // otherwise it returns nil.
17 | func newShake256Asm() ShakeHash {
18 | return nil
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/xor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386,!ppc64le appengine
6 |
7 | package sha3
8 |
9 | var (
10 | xorIn = xorInGeneric
11 | copyOut = copyOutGeneric
12 | xorInUnaligned = xorInGeneric
13 | copyOutUnaligned = copyOutGeneric
14 | )
15 |
16 | const xorImplementationUnaligned = "generic"
17 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/sha3/xor_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package sha3
6 |
7 | import "encoding/binary"
8 |
9 | // xorInGeneric xors the bytes in buf into the state; it
10 | // makes no non-portable assumptions about memory layout
11 | // or alignment.
12 | func xorInGeneric(d *state, buf []byte) {
13 | n := len(buf) / 8
14 |
15 | for i := 0; i < n; i++ {
16 | a := binary.LittleEndian.Uint64(buf)
17 | d.a[i] ^= a
18 | buf = buf[8:]
19 | }
20 | }
21 |
22 | // copyOutGeneric copies ulint64s to a byte buffer.
23 | func copyOutGeneric(d *state, b []byte) {
24 | for i := 0; len(b) >= 8; i++ {
25 | binary.LittleEndian.PutUint64(b, d.a[i])
26 | b = b[8:]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package ssh implements an SSH client and server.
7 |
8 | SSH is a transport security protocol, an authentication protocol and a
9 | family of application protocols. The most typical application level
10 | protocol is a remote shell and this is specifically implemented. However,
11 | the multiplexed nature of SSH is exposed to users that wish to support
12 | others.
13 |
14 | References:
15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
17 |
18 | This package does not fall under the stability promise of the Go language itself,
19 | so its API may be changed when pressing needs arise.
20 | */
21 | package ssh // import "golang.org/x/crypto/ssh"
22 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/tcpip_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func TestAutoPortListenBroken(t *testing.T) {
12 | broken := "SSH-2.0-OpenSSH_5.9hh11"
13 | works := "SSH-2.0-OpenSSH_6.1"
14 | if !isBrokenOpenSSHVersion(broken) {
15 | t.Errorf("version %q not marked as broken", broken)
16 | }
17 | if isBrokenOpenSSHVersion(works) {
18 | t.Errorf("version %q marked as broken", works)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/terminal/util_bsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd netbsd openbsd
6 |
7 | package terminal
8 |
9 | import "golang.org/x/sys/unix"
10 |
11 | const ioctlReadTermios = unix.TIOCGETA
12 | const ioctlWriteTermios = unix.TIOCSETA
13 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/terminal/util_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package terminal
6 |
7 | import "golang.org/x/sys/unix"
8 |
9 | const ioctlReadTermios = unix.TCGETS
10 | const ioctlWriteTermios = unix.TCSETS
11 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/test/banner_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd linux netbsd openbsd
6 |
7 | package test
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func TestBannerCallbackAgainstOpenSSH(t *testing.T) {
14 | server := newServer(t)
15 | defer server.Shutdown()
16 |
17 | clientConf := clientConfig()
18 |
19 | var receivedBanner string
20 | clientConf.BannerCallback = func(message string) error {
21 | receivedBanner = message
22 | return nil
23 | }
24 |
25 | conn := server.Dial(clientConf)
26 | defer conn.Close()
27 |
28 | expected := "Server Banner"
29 | if receivedBanner != expected {
30 | t.Fatalf("got %v; want %v", receivedBanner, expected)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/test/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package test contains integration tests for the
6 | // golang.org/x/crypto/ssh package.
7 | package test // import "golang.org/x/crypto/ssh/test"
8 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/golang.org/x/crypto/ssh/testdata/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This package contains test data shared between the various subpackages of
6 | // the golang.org/x/crypto/ssh package. Under no circumstance should
7 | // this data be used for production code.
8 | package testdata // import "golang.org/x/crypto/ssh/testdata"
9 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/images/bitcoinAddress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/01.比特币钱包的实现/images/bitcoinAddress.png
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/01.比特币钱包的实现/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/.gitattributes:
--------------------------------------------------------------------------------
1 | # Treat all files in this repo as binary, with no git magic updating
2 | # line endings. Windows users contributing to Go will need to use a
3 | # modern version of git and editors capable of LF line endings.
4 | #
5 | # We'll prevent accidental CRLF line endings from entering the repo
6 | # via the git-review gofmt checks.
7 | #
8 | # See golang.org/issue/9281
9 |
10 | * -text
11 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .hgignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at https://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 | ## Filing issues
8 |
9 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
10 |
11 | 1. What version of Go are you using (`go version`)?
12 | 2. What operating system and processor architecture are you using?
13 | 3. What did you do?
14 | 4. What did you expect to see?
15 | 5. What did you see instead?
16 |
17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
19 |
20 | ## Contributing code
21 |
22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23 | before sending patches.
24 |
25 | Unless otherwise noted, the Go source files are distributed under
26 | the BSD-style license found in the LICENSE file.
27 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at https://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/README.md:
--------------------------------------------------------------------------------
1 | # Go Cryptography
2 |
3 | This repository holds supplementary Go cryptography libraries.
4 |
5 | ## Download/Install
6 |
7 | The easiest way to install is to run `go get -u golang.org/x/crypto/...`. You
8 | can also manually git clone the repository to `$GOPATH/src/golang.org/x/crypto`.
9 |
10 | ## Report Issues / Send Patches
11 |
12 | This repository uses Gerrit for code changes. To learn how to submit changes to
13 | this repository, see https://golang.org/doc/contribute.html.
14 |
15 | The main issue tracker for the crypto repository is located at
16 | https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the
17 | subject line, so it is easy to find.
18 |
19 | Note that contributions to the cryptography package receive additional scrutiny
20 | due to their sensitive nature. Patches may take longer than normal to receive
21 | feedback.
22 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/acme/autocert/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package autocert_test
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "net/http"
11 |
12 | "golang.org/x/crypto/acme/autocert"
13 | )
14 |
15 | func ExampleNewListener() {
16 | mux := http.NewServeMux()
17 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
19 | })
20 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
21 | }
22 |
23 | func ExampleManager() {
24 | m := &autocert.Manager{
25 | Cache: autocert.DirCache("secret-dir"),
26 | Prompt: autocert.AcceptTOS,
27 | HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
28 | }
29 | s := &http.Server{
30 | Addr: ":https",
31 | TLSConfig: m.TLSConfig(),
32 | }
33 | s.ListenAndServeTLS("", "")
34 | }
35 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/argon2/blamka_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package argon2
8 |
9 | func processBlock(out, in1, in2 *block) {
10 | processBlockGeneric(out, in1, in2, false)
11 | }
12 |
13 | func processBlockXOR(out, in1, in2 *block) {
14 | processBlockGeneric(out, in1, in2, true)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/bcrypt/base64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bcrypt
6 |
7 | import "encoding/base64"
8 |
9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
10 |
11 | var bcEncoding = base64.NewEncoding(alphabet)
12 |
13 | func base64Encode(src []byte) []byte {
14 | n := bcEncoding.EncodedLen(len(src))
15 | dst := make([]byte, n)
16 | bcEncoding.Encode(dst, src)
17 | for dst[n-1] == '=' {
18 | n--
19 | }
20 | return dst[:n]
21 | }
22 |
23 | func base64Decode(src []byte) ([]byte, error) {
24 | numOfEquals := 4 - (len(src) % 4)
25 | for i := 0; i < numOfEquals; i++ {
26 | src = append(src, '=')
27 | }
28 |
29 | dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 | n, err := bcEncoding.Decode(dst, src)
31 | if err != nil {
32 | return nil, err
33 | }
34 | return dst[:n], nil
35 | }
36 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2b/blake2b_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.7,amd64,!gccgo,!appengine
6 |
7 | package blake2b
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | func init() {
12 | useSSE4 = cpu.X86.HasSSE41
13 | }
14 |
15 | //go:noescape
16 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
17 |
18 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
19 | if useSSE4 {
20 | hashBlocksSSE4(h, c, flag, blocks)
21 | } else {
22 | hashBlocksGeneric(h, c, flag, blocks)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2b/blake2b_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package blake2b
8 |
9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
10 | hashBlocksGeneric(h, c, flag, blocks)
11 | }
12 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2b
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 | newHash384 := func() hash.Hash {
20 | h, _ := New384(nil)
21 | return h
22 | }
23 |
24 | newHash512 := func() hash.Hash {
25 | h, _ := New512(nil)
26 | return h
27 | }
28 |
29 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
30 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
31 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2s/blake2s_386.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build 386,!gccgo,!appengine
6 |
7 | package blake2s
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | var (
12 | useSSE4 = false
13 | useSSSE3 = cpu.X86.HasSSSE3
14 | useSSE2 = cpu.X86.HasSSE2
15 | )
16 |
17 | //go:noescape
18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
19 |
20 | //go:noescape
21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
22 |
23 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
24 | switch {
25 | case useSSSE3:
26 | hashBlocksSSSE3(h, c, flag, blocks)
27 | case useSSE2:
28 | hashBlocksSSE2(h, c, flag, blocks)
29 | default:
30 | hashBlocksGeneric(h, c, flag, blocks)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2s/blake2s_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386 gccgo appengine
6 |
7 | package blake2s
8 |
9 | var (
10 | useSSE4 = false
11 | useSSSE3 = false
12 | useSSE2 = false
13 | )
14 |
15 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
16 | hashBlocksGeneric(h, c, flag, blocks)
17 | }
18 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/blake2s/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2s
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 |
20 | crypto.RegisterHash(crypto.BLAKE2s_256, newHash256)
21 | }
22 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 !go1.7 gccgo appengine
6 |
7 | package chacha20poly1305
8 |
9 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte {
10 | return c.sealGeneric(dst, nonce, plaintext, additionalData)
11 | }
12 |
13 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
14 | return c.openGeneric(dst, nonce, ciphertext, additionalData)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/curve25519/const_amd64.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | #define REDMASK51 0x0007FFFFFFFFFFFF
9 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/curve25519/const_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // These constants cannot be encoded in non-MOVQ immediates.
11 | // We access them directly from memory instead.
12 |
13 | DATA ·_121666_213(SB)/8, $996687872
14 | GLOBL ·_121666_213(SB), 8, $8
15 |
16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA
17 | GLOBL ·_2P0(SB), 8, $8
18 |
19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE
20 | GLOBL ·_2P1234(SB), 8, $8
21 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/curve25519/curve25519_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package curve25519
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 | )
11 |
12 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
13 |
14 | func TestBaseScalarMult(t *testing.T) {
15 | var a, b [32]byte
16 | in := &a
17 | out := &b
18 | a[0] = 1
19 |
20 | for i := 0; i < 200; i++ {
21 | ScalarBaseMult(out, in)
22 | in, out = out, in
23 | }
24 |
25 | result := fmt.Sprintf("%x", in[:])
26 | if result != expectedHex {
27 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
28 | }
29 | }
30 |
31 | func BenchmarkScalarBaseMult(b *testing.B) {
32 | var in, out [32]byte
33 | in[0] = 1
34 |
35 | b.SetBytes(32)
36 | for i := 0; i < b.N; i++ {
37 | ScalarBaseMult(&out, &in)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ed25519/testdata/sign.input.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ed25519/testdata/sign.input.gz
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/internal/chacha20/chacha_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !s390x gccgo appengine
6 |
7 | package chacha20
8 |
9 | const (
10 | bufSize = 64
11 | haveAsm = false
12 | )
13 |
14 | func (*Cipher) xorKeyStreamAsm(dst, src []byte) {
15 | panic("not implemented")
16 | }
17 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/md4/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package md4_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 |
11 | "golang.org/x/crypto/md4"
12 | )
13 |
14 | func ExampleNew() {
15 | h := md4.New()
16 | data := "These pretzels are making me thirsty."
17 | io.WriteString(h, data)
18 | fmt.Printf("%x", h.Sum(nil))
19 | // Output: 48c4e365090b30a32f084c4888deceaa
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/pkcs12/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package pkcs12
6 |
7 | import "errors"
8 |
9 | var (
10 | // ErrDecryption represents a failure to decrypt the input.
11 | ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding")
12 |
13 | // ErrIncorrectPassword is returned when an incorrect password is detected.
14 | // Usually, P12/PFX data is signed to be able to verify the password.
15 | ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect")
16 | )
17 |
18 | // NotImplementedError indicates that the input is not currently supported.
19 | type NotImplementedError string
20 |
21 | func (e NotImplementedError) Error() string {
22 | return "pkcs12: " + string(e)
23 | }
24 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package rc2
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func BenchmarkEncrypt(b *testing.B) {
12 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
13 | b.ResetTimer()
14 | var src [8]byte
15 | for i := 0; i < b.N; i++ {
16 | r.Encrypt(src[:], src[:])
17 | }
18 | }
19 |
20 | func BenchmarkDecrypt(b *testing.B) {
21 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
22 | b.ResetTimer()
23 | var src [8]byte
24 | for i := 0; i < b.N; i++ {
25 | r.Decrypt(src[:], src[:])
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/poly1305/sum_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!gccgo,!appengine
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_amd64.s
10 | //go:noescape
11 | func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305(out, mPtr, uint64(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/poly1305/sum_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build arm,!gccgo,!appengine,!nacl
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_arm.s
10 | //go:noescape
11 | func poly1305_auth_armv6(out *[16]byte, m *byte, mlen uint32, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305_auth_armv6(out, mPtr, uint32(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/poly1305/sum_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build s390x,!go1.11 !arm,!amd64,!s390x gccgo appengine nacl
6 |
7 | package poly1305
8 |
9 | // Sum generates an authenticator for msg using a one-time key and puts the
10 | // 16-byte result into out. Authenticating two different messages with the same
11 | // key allows an attacker to forge messages at will.
12 | func Sum(out *[TagSize]byte, msg []byte, key *[32]byte) {
13 | sumGeneric(out, msg, key)
14 | }
15 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package salsa
8 |
9 | // This function is implemented in salsa2020_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte)
14 |
15 | // XORKeyStream crypts bytes from in to out using the given key and counters.
16 | // In and out must overlap entirely or not at all. Counter
17 | // contains the raw salsa20 counter bytes (both nonce and block counter).
18 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
19 | if len(in) == 0 {
20 | return
21 | }
22 | _ = out[len(in)-1]
23 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0])
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/scrypt/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package scrypt_test
6 |
7 | import (
8 | "encoding/base64"
9 | "fmt"
10 | "log"
11 |
12 | "golang.org/x/crypto/scrypt"
13 | )
14 |
15 | func Example() {
16 | // DO NOT use this salt value; generate your own random salt. 8 bytes is
17 | // a good length.
18 | salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b}
19 |
20 | dk, err := scrypt.Key([]byte("some password"), salt, 1<<15, 8, 1, 32)
21 | if err != nil {
22 | log.Fatal(err)
23 | }
24 | fmt.Println(base64.StdEncoding.EncodeToString(dk))
25 | // Output: lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M=
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/hashes_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | import (
10 | "hash"
11 | )
12 |
13 | // new224Asm returns an assembly implementation of SHA3-224 if available,
14 | // otherwise it returns nil.
15 | func new224Asm() hash.Hash { return nil }
16 |
17 | // new256Asm returns an assembly implementation of SHA3-256 if available,
18 | // otherwise it returns nil.
19 | func new256Asm() hash.Hash { return nil }
20 |
21 | // new384Asm returns an assembly implementation of SHA3-384 if available,
22 | // otherwise it returns nil.
23 | func new384Asm() hash.Hash { return nil }
24 |
25 | // new512Asm returns an assembly implementation of SHA3-512 if available,
26 | // otherwise it returns nil.
27 | func new512Asm() hash.Hash { return nil }
28 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/keccakf_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package sha3
8 |
9 | // This function is implemented in keccakf_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func keccakF1600(a *[25]uint64)
14 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.4
6 |
7 | package sha3
8 |
9 | import (
10 | "crypto"
11 | )
12 |
13 | func init() {
14 | crypto.RegisterHash(crypto.SHA3_224, New224)
15 | crypto.RegisterHash(crypto.SHA3_256, New256)
16 | crypto.RegisterHash(crypto.SHA3_384, New384)
17 | crypto.RegisterHash(crypto.SHA3_512, New512)
18 | }
19 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/shake_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
10 | // otherwise it returns nil.
11 | func newShake128Asm() ShakeHash {
12 | return nil
13 | }
14 |
15 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
16 | // otherwise it returns nil.
17 | func newShake256Asm() ShakeHash {
18 | return nil
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/xor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386,!ppc64le appengine
6 |
7 | package sha3
8 |
9 | var (
10 | xorIn = xorInGeneric
11 | copyOut = copyOutGeneric
12 | xorInUnaligned = xorInGeneric
13 | copyOutUnaligned = copyOutGeneric
14 | )
15 |
16 | const xorImplementationUnaligned = "generic"
17 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/sha3/xor_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package sha3
6 |
7 | import "encoding/binary"
8 |
9 | // xorInGeneric xors the bytes in buf into the state; it
10 | // makes no non-portable assumptions about memory layout
11 | // or alignment.
12 | func xorInGeneric(d *state, buf []byte) {
13 | n := len(buf) / 8
14 |
15 | for i := 0; i < n; i++ {
16 | a := binary.LittleEndian.Uint64(buf)
17 | d.a[i] ^= a
18 | buf = buf[8:]
19 | }
20 | }
21 |
22 | // copyOutGeneric copies ulint64s to a byte buffer.
23 | func copyOutGeneric(d *state, b []byte) {
24 | for i := 0; len(b) >= 8; i++ {
25 | binary.LittleEndian.PutUint64(b, d.a[i])
26 | b = b[8:]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package ssh implements an SSH client and server.
7 |
8 | SSH is a transport security protocol, an authentication protocol and a
9 | family of application protocols. The most typical application level
10 | protocol is a remote shell and this is specifically implemented. However,
11 | the multiplexed nature of SSH is exposed to users that wish to support
12 | others.
13 |
14 | References:
15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
17 |
18 | This package does not fall under the stability promise of the Go language itself,
19 | so its API may be changed when pressing needs arise.
20 | */
21 | package ssh // import "golang.org/x/crypto/ssh"
22 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/tcpip_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func TestAutoPortListenBroken(t *testing.T) {
12 | broken := "SSH-2.0-OpenSSH_5.9hh11"
13 | works := "SSH-2.0-OpenSSH_6.1"
14 | if !isBrokenOpenSSHVersion(broken) {
15 | t.Errorf("version %q not marked as broken", broken)
16 | }
17 | if isBrokenOpenSSHVersion(works) {
18 | t.Errorf("version %q marked as broken", works)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/terminal/util_bsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd netbsd openbsd
6 |
7 | package terminal
8 |
9 | import "golang.org/x/sys/unix"
10 |
11 | const ioctlReadTermios = unix.TIOCGETA
12 | const ioctlWriteTermios = unix.TIOCSETA
13 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/terminal/util_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package terminal
6 |
7 | import "golang.org/x/sys/unix"
8 |
9 | const ioctlReadTermios = unix.TCGETS
10 | const ioctlWriteTermios = unix.TCSETS
11 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/test/banner_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd linux netbsd openbsd
6 |
7 | package test
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func TestBannerCallbackAgainstOpenSSH(t *testing.T) {
14 | server := newServer(t)
15 | defer server.Shutdown()
16 |
17 | clientConf := clientConfig()
18 |
19 | var receivedBanner string
20 | clientConf.BannerCallback = func(message string) error {
21 | receivedBanner = message
22 | return nil
23 | }
24 |
25 | conn := server.Dial(clientConf)
26 | defer conn.Close()
27 |
28 | expected := "Server Banner"
29 | if receivedBanner != expected {
30 | t.Fatalf("got %v; want %v", receivedBanner, expected)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/test/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package test contains integration tests for the
6 | // golang.org/x/crypto/ssh package.
7 | package test // import "golang.org/x/crypto/ssh/test"
8 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/golang.org/x/crypto/ssh/testdata/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This package contains test data shared between the various subpackages of
6 | // the golang.org/x/crypto/ssh package. Under no circumstance should
7 | // this data be used for production code.
8 | package testdata // import "golang.org/x/crypto/ssh/testdata"
9 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/blockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type Blockchain struct {
4 | blocks []*Block
5 | }
6 |
7 | func (bc *Blockchain) AddBlock(transactions []*Transaction){
8 | //获取上一个
9 | prevBlock := bc.blocks[ len(bc.blocks) - 1 ]
10 | //创建一个区块
11 | newBlock := NewBlock(transactions,prevBlock.Hash)
12 | //把区块加入区块链中
13 | bc.blocks = append(bc.blocks,newBlock)
14 | }
15 |
16 | //创建拥有创世区块的区块链
17 | func NewBlockchain(block *Block) *Blockchain{
18 | return &Blockchain{[]*Block{block}}
19 | }
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/transaction.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "encoding/gob"
6 | "bytes"
7 | )
8 |
9 | type Transaction struct{
10 | ID []byte
11 | Vint []TXInput
12 | Vout []TXOutput
13 | }
14 |
15 | func (tx Transaction) Serialize() []byte {
16 | var buffer bytes.Buffer
17 | encoder := gob.NewEncoder(&buffer)
18 | err := encoder.Encode(tx)
19 | if err != nil {
20 | log.Panic(err)
21 | }
22 | return buffer.Bytes()
23 | }
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 |
4 | type TXInput struct{
5 | Txid []byte
6 | Vout int
7 | Signature []byte
8 | PubKey []byte
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type TXOutput struct {
4 | Value int
5 | PubKeyHash []byte
6 | }
--------------------------------------------------------------------------------
/代币底层实现/02.区块链数据结构的实现-1/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/.gitattributes:
--------------------------------------------------------------------------------
1 | # Treat all files in this repo as binary, with no git magic updating
2 | # line endings. Windows users contributing to Go will need to use a
3 | # modern version of git and editors capable of LF line endings.
4 | #
5 | # We'll prevent accidental CRLF line endings from entering the repo
6 | # via the git-review gofmt checks.
7 | #
8 | # See golang.org/issue/9281
9 |
10 | * -text
11 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .hgignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at https://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 | ## Filing issues
8 |
9 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
10 |
11 | 1. What version of Go are you using (`go version`)?
12 | 2. What operating system and processor architecture are you using?
13 | 3. What did you do?
14 | 4. What did you expect to see?
15 | 5. What did you see instead?
16 |
17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
19 |
20 | ## Contributing code
21 |
22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23 | before sending patches.
24 |
25 | Unless otherwise noted, the Go source files are distributed under
26 | the BSD-style license found in the LICENSE file.
27 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at https://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/README.md:
--------------------------------------------------------------------------------
1 | # Go Cryptography
2 |
3 | This repository holds supplementary Go cryptography libraries.
4 |
5 | ## Download/Install
6 |
7 | The easiest way to install is to run `go get -u golang.org/x/crypto/...`. You
8 | can also manually git clone the repository to `$GOPATH/src/golang.org/x/crypto`.
9 |
10 | ## Report Issues / Send Patches
11 |
12 | This repository uses Gerrit for code changes. To learn how to submit changes to
13 | this repository, see https://golang.org/doc/contribute.html.
14 |
15 | The main issue tracker for the crypto repository is located at
16 | https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the
17 | subject line, so it is easy to find.
18 |
19 | Note that contributions to the cryptography package receive additional scrutiny
20 | due to their sensitive nature. Patches may take longer than normal to receive
21 | feedback.
22 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/acme/autocert/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package autocert_test
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "net/http"
11 |
12 | "golang.org/x/crypto/acme/autocert"
13 | )
14 |
15 | func ExampleNewListener() {
16 | mux := http.NewServeMux()
17 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
19 | })
20 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
21 | }
22 |
23 | func ExampleManager() {
24 | m := &autocert.Manager{
25 | Cache: autocert.DirCache("secret-dir"),
26 | Prompt: autocert.AcceptTOS,
27 | HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
28 | }
29 | s := &http.Server{
30 | Addr: ":https",
31 | TLSConfig: m.TLSConfig(),
32 | }
33 | s.ListenAndServeTLS("", "")
34 | }
35 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/argon2/blamka_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package argon2
8 |
9 | func processBlock(out, in1, in2 *block) {
10 | processBlockGeneric(out, in1, in2, false)
11 | }
12 |
13 | func processBlockXOR(out, in1, in2 *block) {
14 | processBlockGeneric(out, in1, in2, true)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/bcrypt/base64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bcrypt
6 |
7 | import "encoding/base64"
8 |
9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
10 |
11 | var bcEncoding = base64.NewEncoding(alphabet)
12 |
13 | func base64Encode(src []byte) []byte {
14 | n := bcEncoding.EncodedLen(len(src))
15 | dst := make([]byte, n)
16 | bcEncoding.Encode(dst, src)
17 | for dst[n-1] == '=' {
18 | n--
19 | }
20 | return dst[:n]
21 | }
22 |
23 | func base64Decode(src []byte) ([]byte, error) {
24 | numOfEquals := 4 - (len(src) % 4)
25 | for i := 0; i < numOfEquals; i++ {
26 | src = append(src, '=')
27 | }
28 |
29 | dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 | n, err := bcEncoding.Decode(dst, src)
31 | if err != nil {
32 | return nil, err
33 | }
34 | return dst[:n], nil
35 | }
36 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2b/blake2b_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.7,amd64,!gccgo,!appengine
6 |
7 | package blake2b
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | func init() {
12 | useSSE4 = cpu.X86.HasSSE41
13 | }
14 |
15 | //go:noescape
16 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
17 |
18 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
19 | if useSSE4 {
20 | hashBlocksSSE4(h, c, flag, blocks)
21 | } else {
22 | hashBlocksGeneric(h, c, flag, blocks)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2b/blake2b_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package blake2b
8 |
9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
10 | hashBlocksGeneric(h, c, flag, blocks)
11 | }
12 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2b
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 | newHash384 := func() hash.Hash {
20 | h, _ := New384(nil)
21 | return h
22 | }
23 |
24 | newHash512 := func() hash.Hash {
25 | h, _ := New512(nil)
26 | return h
27 | }
28 |
29 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
30 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
31 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2s/blake2s_386.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build 386,!gccgo,!appengine
6 |
7 | package blake2s
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | var (
12 | useSSE4 = false
13 | useSSSE3 = cpu.X86.HasSSSE3
14 | useSSE2 = cpu.X86.HasSSE2
15 | )
16 |
17 | //go:noescape
18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
19 |
20 | //go:noescape
21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
22 |
23 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
24 | switch {
25 | case useSSSE3:
26 | hashBlocksSSSE3(h, c, flag, blocks)
27 | case useSSE2:
28 | hashBlocksSSE2(h, c, flag, blocks)
29 | default:
30 | hashBlocksGeneric(h, c, flag, blocks)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2s/blake2s_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386 gccgo appengine
6 |
7 | package blake2s
8 |
9 | var (
10 | useSSE4 = false
11 | useSSSE3 = false
12 | useSSE2 = false
13 | )
14 |
15 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
16 | hashBlocksGeneric(h, c, flag, blocks)
17 | }
18 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/blake2s/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2s
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 |
20 | crypto.RegisterHash(crypto.BLAKE2s_256, newHash256)
21 | }
22 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 !go1.7 gccgo appengine
6 |
7 | package chacha20poly1305
8 |
9 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte {
10 | return c.sealGeneric(dst, nonce, plaintext, additionalData)
11 | }
12 |
13 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
14 | return c.openGeneric(dst, nonce, ciphertext, additionalData)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/curve25519/const_amd64.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | #define REDMASK51 0x0007FFFFFFFFFFFF
9 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/curve25519/const_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // These constants cannot be encoded in non-MOVQ immediates.
11 | // We access them directly from memory instead.
12 |
13 | DATA ·_121666_213(SB)/8, $996687872
14 | GLOBL ·_121666_213(SB), 8, $8
15 |
16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA
17 | GLOBL ·_2P0(SB), 8, $8
18 |
19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE
20 | GLOBL ·_2P1234(SB), 8, $8
21 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/curve25519/curve25519_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package curve25519
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 | )
11 |
12 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
13 |
14 | func TestBaseScalarMult(t *testing.T) {
15 | var a, b [32]byte
16 | in := &a
17 | out := &b
18 | a[0] = 1
19 |
20 | for i := 0; i < 200; i++ {
21 | ScalarBaseMult(out, in)
22 | in, out = out, in
23 | }
24 |
25 | result := fmt.Sprintf("%x", in[:])
26 | if result != expectedHex {
27 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
28 | }
29 | }
30 |
31 | func BenchmarkScalarBaseMult(b *testing.B) {
32 | var in, out [32]byte
33 | in[0] = 1
34 |
35 | b.SetBytes(32)
36 | for i := 0; i < b.N; i++ {
37 | ScalarBaseMult(&out, &in)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ed25519/testdata/sign.input.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ed25519/testdata/sign.input.gz
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/internal/chacha20/chacha_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !s390x gccgo appengine
6 |
7 | package chacha20
8 |
9 | const (
10 | bufSize = 64
11 | haveAsm = false
12 | )
13 |
14 | func (*Cipher) xorKeyStreamAsm(dst, src []byte) {
15 | panic("not implemented")
16 | }
17 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/md4/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package md4_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 |
11 | "golang.org/x/crypto/md4"
12 | )
13 |
14 | func ExampleNew() {
15 | h := md4.New()
16 | data := "These pretzels are making me thirsty."
17 | io.WriteString(h, data)
18 | fmt.Printf("%x", h.Sum(nil))
19 | // Output: 48c4e365090b30a32f084c4888deceaa
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/pkcs12/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package pkcs12
6 |
7 | import "errors"
8 |
9 | var (
10 | // ErrDecryption represents a failure to decrypt the input.
11 | ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding")
12 |
13 | // ErrIncorrectPassword is returned when an incorrect password is detected.
14 | // Usually, P12/PFX data is signed to be able to verify the password.
15 | ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect")
16 | )
17 |
18 | // NotImplementedError indicates that the input is not currently supported.
19 | type NotImplementedError string
20 |
21 | func (e NotImplementedError) Error() string {
22 | return "pkcs12: " + string(e)
23 | }
24 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package rc2
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func BenchmarkEncrypt(b *testing.B) {
12 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
13 | b.ResetTimer()
14 | var src [8]byte
15 | for i := 0; i < b.N; i++ {
16 | r.Encrypt(src[:], src[:])
17 | }
18 | }
19 |
20 | func BenchmarkDecrypt(b *testing.B) {
21 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
22 | b.ResetTimer()
23 | var src [8]byte
24 | for i := 0; i < b.N; i++ {
25 | r.Decrypt(src[:], src[:])
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/poly1305/sum_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!gccgo,!appengine
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_amd64.s
10 | //go:noescape
11 | func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305(out, mPtr, uint64(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/poly1305/sum_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build arm,!gccgo,!appengine,!nacl
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_arm.s
10 | //go:noescape
11 | func poly1305_auth_armv6(out *[16]byte, m *byte, mlen uint32, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305_auth_armv6(out, mPtr, uint32(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/poly1305/sum_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build s390x,!go1.11 !arm,!amd64,!s390x gccgo appengine nacl
6 |
7 | package poly1305
8 |
9 | // Sum generates an authenticator for msg using a one-time key and puts the
10 | // 16-byte result into out. Authenticating two different messages with the same
11 | // key allows an attacker to forge messages at will.
12 | func Sum(out *[TagSize]byte, msg []byte, key *[32]byte) {
13 | sumGeneric(out, msg, key)
14 | }
15 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package salsa
8 |
9 | // This function is implemented in salsa2020_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte)
14 |
15 | // XORKeyStream crypts bytes from in to out using the given key and counters.
16 | // In and out must overlap entirely or not at all. Counter
17 | // contains the raw salsa20 counter bytes (both nonce and block counter).
18 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
19 | if len(in) == 0 {
20 | return
21 | }
22 | _ = out[len(in)-1]
23 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0])
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/scrypt/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package scrypt_test
6 |
7 | import (
8 | "encoding/base64"
9 | "fmt"
10 | "log"
11 |
12 | "golang.org/x/crypto/scrypt"
13 | )
14 |
15 | func Example() {
16 | // DO NOT use this salt value; generate your own random salt. 8 bytes is
17 | // a good length.
18 | salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b}
19 |
20 | dk, err := scrypt.Key([]byte("some password"), salt, 1<<15, 8, 1, 32)
21 | if err != nil {
22 | log.Fatal(err)
23 | }
24 | fmt.Println(base64.StdEncoding.EncodeToString(dk))
25 | // Output: lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M=
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/hashes_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | import (
10 | "hash"
11 | )
12 |
13 | // new224Asm returns an assembly implementation of SHA3-224 if available,
14 | // otherwise it returns nil.
15 | func new224Asm() hash.Hash { return nil }
16 |
17 | // new256Asm returns an assembly implementation of SHA3-256 if available,
18 | // otherwise it returns nil.
19 | func new256Asm() hash.Hash { return nil }
20 |
21 | // new384Asm returns an assembly implementation of SHA3-384 if available,
22 | // otherwise it returns nil.
23 | func new384Asm() hash.Hash { return nil }
24 |
25 | // new512Asm returns an assembly implementation of SHA3-512 if available,
26 | // otherwise it returns nil.
27 | func new512Asm() hash.Hash { return nil }
28 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/keccakf_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package sha3
8 |
9 | // This function is implemented in keccakf_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func keccakF1600(a *[25]uint64)
14 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.4
6 |
7 | package sha3
8 |
9 | import (
10 | "crypto"
11 | )
12 |
13 | func init() {
14 | crypto.RegisterHash(crypto.SHA3_224, New224)
15 | crypto.RegisterHash(crypto.SHA3_256, New256)
16 | crypto.RegisterHash(crypto.SHA3_384, New384)
17 | crypto.RegisterHash(crypto.SHA3_512, New512)
18 | }
19 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/shake_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
10 | // otherwise it returns nil.
11 | func newShake128Asm() ShakeHash {
12 | return nil
13 | }
14 |
15 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
16 | // otherwise it returns nil.
17 | func newShake256Asm() ShakeHash {
18 | return nil
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/xor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386,!ppc64le appengine
6 |
7 | package sha3
8 |
9 | var (
10 | xorIn = xorInGeneric
11 | copyOut = copyOutGeneric
12 | xorInUnaligned = xorInGeneric
13 | copyOutUnaligned = copyOutGeneric
14 | )
15 |
16 | const xorImplementationUnaligned = "generic"
17 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/sha3/xor_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package sha3
6 |
7 | import "encoding/binary"
8 |
9 | // xorInGeneric xors the bytes in buf into the state; it
10 | // makes no non-portable assumptions about memory layout
11 | // or alignment.
12 | func xorInGeneric(d *state, buf []byte) {
13 | n := len(buf) / 8
14 |
15 | for i := 0; i < n; i++ {
16 | a := binary.LittleEndian.Uint64(buf)
17 | d.a[i] ^= a
18 | buf = buf[8:]
19 | }
20 | }
21 |
22 | // copyOutGeneric copies ulint64s to a byte buffer.
23 | func copyOutGeneric(d *state, b []byte) {
24 | for i := 0; len(b) >= 8; i++ {
25 | binary.LittleEndian.PutUint64(b, d.a[i])
26 | b = b[8:]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package ssh implements an SSH client and server.
7 |
8 | SSH is a transport security protocol, an authentication protocol and a
9 | family of application protocols. The most typical application level
10 | protocol is a remote shell and this is specifically implemented. However,
11 | the multiplexed nature of SSH is exposed to users that wish to support
12 | others.
13 |
14 | References:
15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
17 |
18 | This package does not fall under the stability promise of the Go language itself,
19 | so its API may be changed when pressing needs arise.
20 | */
21 | package ssh // import "golang.org/x/crypto/ssh"
22 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/tcpip_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func TestAutoPortListenBroken(t *testing.T) {
12 | broken := "SSH-2.0-OpenSSH_5.9hh11"
13 | works := "SSH-2.0-OpenSSH_6.1"
14 | if !isBrokenOpenSSHVersion(broken) {
15 | t.Errorf("version %q not marked as broken", broken)
16 | }
17 | if isBrokenOpenSSHVersion(works) {
18 | t.Errorf("version %q marked as broken", works)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/terminal/util_bsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd netbsd openbsd
6 |
7 | package terminal
8 |
9 | import "golang.org/x/sys/unix"
10 |
11 | const ioctlReadTermios = unix.TIOCGETA
12 | const ioctlWriteTermios = unix.TIOCSETA
13 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/terminal/util_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package terminal
6 |
7 | import "golang.org/x/sys/unix"
8 |
9 | const ioctlReadTermios = unix.TCGETS
10 | const ioctlWriteTermios = unix.TCSETS
11 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/test/banner_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd linux netbsd openbsd
6 |
7 | package test
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func TestBannerCallbackAgainstOpenSSH(t *testing.T) {
14 | server := newServer(t)
15 | defer server.Shutdown()
16 |
17 | clientConf := clientConfig()
18 |
19 | var receivedBanner string
20 | clientConf.BannerCallback = func(message string) error {
21 | receivedBanner = message
22 | return nil
23 | }
24 |
25 | conn := server.Dial(clientConf)
26 | defer conn.Close()
27 |
28 | expected := "Server Banner"
29 | if receivedBanner != expected {
30 | t.Fatalf("got %v; want %v", receivedBanner, expected)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/test/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package test contains integration tests for the
6 | // golang.org/x/crypto/ssh package.
7 | package test // import "golang.org/x/crypto/ssh/test"
8 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/golang.org/x/crypto/ssh/testdata/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This package contains test data shared between the various subpackages of
6 | // the golang.org/x/crypto/ssh package. Under no circumstance should
7 | // this data be used for production code.
8 | package testdata // import "golang.org/x/crypto/ssh/testdata"
9 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/blockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type Blockchain struct {
4 | blocks []*Block
5 | }
6 |
7 | func (bc *Blockchain) AddBlock(transactions []*Transaction){
8 | //获取上一个
9 | prevBlock := bc.blocks[ len(bc.blocks) - 1 ]
10 | //创建一个区块
11 | newBlock := NewBlock(transactions,prevBlock.Hash)
12 | //把区块加入区块链中
13 | bc.blocks = append(bc.blocks,newBlock)
14 | }
15 |
16 | //创建拥有创世区块的区块链
17 | func NewBlockchain(block *Block) *Blockchain{
18 | return &Blockchain{[]*Block{block}}
19 | }
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/transaction.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "encoding/gob"
6 | "bytes"
7 | )
8 |
9 | type Transaction struct{
10 | ID []byte
11 | Vint []TXInput
12 | Vout []TXOutput
13 | }
14 |
15 | func (tx Transaction) Serialize() []byte {
16 | var buffer bytes.Buffer
17 | encoder := gob.NewEncoder(&buffer)
18 | err := encoder.Encode(tx)
19 | if err != nil {
20 | log.Panic(err)
21 | }
22 | return buffer.Bytes()
23 | }
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 |
4 | type TXInput struct{
5 | Txid []byte
6 | Vout int
7 | Signature []byte
8 | PubKey []byte
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type TXOutput struct {
4 | Value int
5 | PubKeyHash []byte
6 | }
--------------------------------------------------------------------------------
/代币底层实现/03.工作量证明_挖矿的实现/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/blotdbDemo/student.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/gob"
6 | "fmt"
7 | "log"
8 | )
9 |
10 | type Student struct {
11 | Id int
12 | Name string
13 | School string
14 | }
15 |
16 | //创建一个学生
17 | func NewStudent(id int, name, school string) *Student {
18 | return &Student{id, name, school}
19 | }
20 |
21 | func (stu *Student) getInfo() {
22 | fmt.Println(stu.Id, stu.Name, stu.School)
23 | }
24 |
25 | //对结构体进行序列化
26 | func (stu *Student) Serialize() []byte {
27 | var buffer bytes.Buffer
28 | encoder := gob.NewEncoder(&buffer)
29 | err := encoder.Encode(stu)
30 | if err != nil {
31 | log.Panic(err)
32 | }
33 | return buffer.Bytes()
34 | }
35 |
36 | func UnSerializeStudent(byteStudentData []byte) *Student {
37 | var student Student
38 | decoder := gob.NewDecoder(bytes.NewReader(byteStudentData))
39 | err := decoder.Decode(&student)
40 | if err != nil {
41 | log.Panic(err)
42 | }
43 | return &student
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/.gitattributes:
--------------------------------------------------------------------------------
1 | # Treat all files in this repo as binary, with no git magic updating
2 | # line endings. Windows users contributing to Go will need to use a
3 | # modern version of git and editors capable of LF line endings.
4 | #
5 | # We'll prevent accidental CRLF line endings from entering the repo
6 | # via the git-review gofmt checks.
7 | #
8 | # See golang.org/issue/9281
9 |
10 | * -text
11 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .hgignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at https://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at https://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/README.md:
--------------------------------------------------------------------------------
1 | # Go Cryptography
2 |
3 | This repository holds supplementary Go cryptography libraries.
4 |
5 | ## Download/Install
6 |
7 | The easiest way to install is to run `go get -u golang.org/x/crypto/...`. You
8 | can also manually git clone the repository to `$GOPATH/src/golang.org/x/crypto`.
9 |
10 | ## Report Issues / Send Patches
11 |
12 | This repository uses Gerrit for code changes. To learn how to submit changes to
13 | this repository, see https://golang.org/doc/contribute.html.
14 |
15 | The main issue tracker for the crypto repository is located at
16 | https://github.com/golang/go/issues. Prefix your issue with "x/crypto:" in the
17 | subject line, so it is easy to find.
18 |
19 | Note that contributions to the cryptography package receive additional scrutiny
20 | due to their sensitive nature. Patches may take longer than normal to receive
21 | feedback.
22 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/acme/autocert/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package autocert_test
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "net/http"
11 |
12 | "golang.org/x/crypto/acme/autocert"
13 | )
14 |
15 | func ExampleNewListener() {
16 | mux := http.NewServeMux()
17 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 | fmt.Fprintf(w, "Hello, TLS user! Your config: %+v", r.TLS)
19 | })
20 | log.Fatal(http.Serve(autocert.NewListener("example.com"), mux))
21 | }
22 |
23 | func ExampleManager() {
24 | m := &autocert.Manager{
25 | Cache: autocert.DirCache("secret-dir"),
26 | Prompt: autocert.AcceptTOS,
27 | HostPolicy: autocert.HostWhitelist("example.org", "www.example.org"),
28 | }
29 | s := &http.Server{
30 | Addr: ":https",
31 | TLSConfig: m.TLSConfig(),
32 | }
33 | s.ListenAndServeTLS("", "")
34 | }
35 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/argon2/blamka_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package argon2
8 |
9 | func processBlock(out, in1, in2 *block) {
10 | processBlockGeneric(out, in1, in2, false)
11 | }
12 |
13 | func processBlockXOR(out, in1, in2 *block) {
14 | processBlockGeneric(out, in1, in2, true)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/bcrypt/base64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bcrypt
6 |
7 | import "encoding/base64"
8 |
9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
10 |
11 | var bcEncoding = base64.NewEncoding(alphabet)
12 |
13 | func base64Encode(src []byte) []byte {
14 | n := bcEncoding.EncodedLen(len(src))
15 | dst := make([]byte, n)
16 | bcEncoding.Encode(dst, src)
17 | for dst[n-1] == '=' {
18 | n--
19 | }
20 | return dst[:n]
21 | }
22 |
23 | func base64Decode(src []byte) ([]byte, error) {
24 | numOfEquals := 4 - (len(src) % 4)
25 | for i := 0; i < numOfEquals; i++ {
26 | src = append(src, '=')
27 | }
28 |
29 | dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 | n, err := bcEncoding.Decode(dst, src)
31 | if err != nil {
32 | return nil, err
33 | }
34 | return dst[:n], nil
35 | }
36 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2b/blake2b_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !go1.7,amd64,!gccgo,!appengine
6 |
7 | package blake2b
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | func init() {
12 | useSSE4 = cpu.X86.HasSSE41
13 | }
14 |
15 | //go:noescape
16 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
17 |
18 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
19 | if useSSE4 {
20 | hashBlocksSSE4(h, c, flag, blocks)
21 | } else {
22 | hashBlocksGeneric(h, c, flag, blocks)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2b/blake2b_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 appengine gccgo
6 |
7 | package blake2b
8 |
9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
10 | hashBlocksGeneric(h, c, flag, blocks)
11 | }
12 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2b
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 | newHash384 := func() hash.Hash {
20 | h, _ := New384(nil)
21 | return h
22 | }
23 |
24 | newHash512 := func() hash.Hash {
25 | h, _ := New512(nil)
26 | return h
27 | }
28 |
29 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
30 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
31 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2s/blake2s_386.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build 386,!gccgo,!appengine
6 |
7 | package blake2s
8 |
9 | import "golang.org/x/sys/cpu"
10 |
11 | var (
12 | useSSE4 = false
13 | useSSSE3 = cpu.X86.HasSSSE3
14 | useSSE2 = cpu.X86.HasSSE2
15 | )
16 |
17 | //go:noescape
18 | func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
19 |
20 | //go:noescape
21 | func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
22 |
23 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
24 | switch {
25 | case useSSSE3:
26 | hashBlocksSSSE3(h, c, flag, blocks)
27 | case useSSE2:
28 | hashBlocksSSE2(h, c, flag, blocks)
29 | default:
30 | hashBlocksGeneric(h, c, flag, blocks)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2s/blake2s_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386 gccgo appengine
6 |
7 | package blake2s
8 |
9 | var (
10 | useSSE4 = false
11 | useSSSE3 = false
12 | useSSE2 = false
13 | )
14 |
15 | func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) {
16 | hashBlocksGeneric(h, c, flag, blocks)
17 | }
18 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/blake2s/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.9
6 |
7 | package blake2s
8 |
9 | import (
10 | "crypto"
11 | "hash"
12 | )
13 |
14 | func init() {
15 | newHash256 := func() hash.Hash {
16 | h, _ := New256(nil)
17 | return h
18 | }
19 |
20 | crypto.RegisterHash(crypto.BLAKE2s_256, newHash256)
21 | }
22 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64 !go1.7 gccgo appengine
6 |
7 | package chacha20poly1305
8 |
9 | func (c *chacha20poly1305) seal(dst, nonce, plaintext, additionalData []byte) []byte {
10 | return c.sealGeneric(dst, nonce, plaintext, additionalData)
11 | }
12 |
13 | func (c *chacha20poly1305) open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
14 | return c.openGeneric(dst, nonce, ciphertext, additionalData)
15 | }
16 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/curve25519/const_amd64.h:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | #define REDMASK51 0x0007FFFFFFFFFFFF
9 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/curve25519/const_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This code was translated into a form compatible with 6a from the public
6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html
7 |
8 | // +build amd64,!gccgo,!appengine
9 |
10 | // These constants cannot be encoded in non-MOVQ immediates.
11 | // We access them directly from memory instead.
12 |
13 | DATA ·_121666_213(SB)/8, $996687872
14 | GLOBL ·_121666_213(SB), 8, $8
15 |
16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA
17 | GLOBL ·_2P0(SB), 8, $8
18 |
19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE
20 | GLOBL ·_2P1234(SB), 8, $8
21 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/curve25519/curve25519_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package curve25519
6 |
7 | import (
8 | "fmt"
9 | "testing"
10 | )
11 |
12 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
13 |
14 | func TestBaseScalarMult(t *testing.T) {
15 | var a, b [32]byte
16 | in := &a
17 | out := &b
18 | a[0] = 1
19 |
20 | for i := 0; i < 200; i++ {
21 | ScalarBaseMult(out, in)
22 | in, out = out, in
23 | }
24 |
25 | result := fmt.Sprintf("%x", in[:])
26 | if result != expectedHex {
27 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
28 | }
29 | }
30 |
31 | func BenchmarkScalarBaseMult(b *testing.B) {
32 | var in, out [32]byte
33 | in[0] = 1
34 |
35 | b.SetBytes(32)
36 | for i := 0; i < b.N; i++ {
37 | ScalarBaseMult(&out, &in)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ed25519/testdata/sign.input.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ed25519/testdata/sign.input.gz
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/internal/chacha20/chacha_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !s390x gccgo appengine
6 |
7 | package chacha20
8 |
9 | const (
10 | bufSize = 64
11 | haveAsm = false
12 | )
13 |
14 | func (*Cipher) xorKeyStreamAsm(dst, src []byte) {
15 | panic("not implemented")
16 | }
17 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/md4/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package md4_test
6 |
7 | import (
8 | "fmt"
9 | "io"
10 |
11 | "golang.org/x/crypto/md4"
12 | )
13 |
14 | func ExampleNew() {
15 | h := md4.New()
16 | data := "These pretzels are making me thirsty."
17 | io.WriteString(h, data)
18 | fmt.Printf("%x", h.Sum(nil))
19 | // Output: 48c4e365090b30a32f084c4888deceaa
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/pkcs12/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package pkcs12
6 |
7 | import "errors"
8 |
9 | var (
10 | // ErrDecryption represents a failure to decrypt the input.
11 | ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding")
12 |
13 | // ErrIncorrectPassword is returned when an incorrect password is detected.
14 | // Usually, P12/PFX data is signed to be able to verify the password.
15 | ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect")
16 | )
17 |
18 | // NotImplementedError indicates that the input is not currently supported.
19 | type NotImplementedError string
20 |
21 | func (e NotImplementedError) Error() string {
22 | return "pkcs12: " + string(e)
23 | }
24 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/pkcs12/internal/rc2/bench_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package rc2
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func BenchmarkEncrypt(b *testing.B) {
12 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
13 | b.ResetTimer()
14 | var src [8]byte
15 | for i := 0; i < b.N; i++ {
16 | r.Encrypt(src[:], src[:])
17 | }
18 | }
19 |
20 | func BenchmarkDecrypt(b *testing.B) {
21 | r, _ := New([]byte{0, 0, 0, 0, 0, 0, 0, 0}, 64)
22 | b.ResetTimer()
23 | var src [8]byte
24 | for i := 0; i < b.N; i++ {
25 | r.Decrypt(src[:], src[:])
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/poly1305/sum_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!gccgo,!appengine
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_amd64.s
10 | //go:noescape
11 | func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305(out, mPtr, uint64(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/poly1305/sum_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build arm,!gccgo,!appengine,!nacl
6 |
7 | package poly1305
8 |
9 | // This function is implemented in sum_arm.s
10 | //go:noescape
11 | func poly1305_auth_armv6(out *[16]byte, m *byte, mlen uint32, key *[32]byte)
12 |
13 | // Sum generates an authenticator for m using a one-time key and puts the
14 | // 16-byte result into out. Authenticating two different messages with the same
15 | // key allows an attacker to forge messages at will.
16 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
17 | var mPtr *byte
18 | if len(m) > 0 {
19 | mPtr = &m[0]
20 | }
21 | poly1305_auth_armv6(out, mPtr, uint32(len(m)), key)
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/poly1305/sum_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build s390x,!go1.11 !arm,!amd64,!s390x gccgo appengine nacl
6 |
7 | package poly1305
8 |
9 | // Sum generates an authenticator for msg using a one-time key and puts the
10 | // 16-byte result into out. Authenticating two different messages with the same
11 | // key allows an attacker to forge messages at will.
12 | func Sum(out *[TagSize]byte, msg []byte, key *[32]byte) {
13 | sumGeneric(out, msg, key)
14 | }
15 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package salsa
8 |
9 | // This function is implemented in salsa2020_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte)
14 |
15 | // XORKeyStream crypts bytes from in to out using the given key and counters.
16 | // In and out must overlap entirely or not at all. Counter
17 | // contains the raw salsa20 counter bytes (both nonce and block counter).
18 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
19 | if len(in) == 0 {
20 | return
21 | }
22 | _ = out[len(in)-1]
23 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0])
24 | }
25 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/scrypt/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package scrypt_test
6 |
7 | import (
8 | "encoding/base64"
9 | "fmt"
10 | "log"
11 |
12 | "golang.org/x/crypto/scrypt"
13 | )
14 |
15 | func Example() {
16 | // DO NOT use this salt value; generate your own random salt. 8 bytes is
17 | // a good length.
18 | salt := []byte{0xc8, 0x28, 0xf2, 0x58, 0xa7, 0x6a, 0xad, 0x7b}
19 |
20 | dk, err := scrypt.Key([]byte("some password"), salt, 1<<15, 8, 1, 32)
21 | if err != nil {
22 | log.Fatal(err)
23 | }
24 | fmt.Println(base64.StdEncoding.EncodeToString(dk))
25 | // Output: lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M=
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/hashes_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | import (
10 | "hash"
11 | )
12 |
13 | // new224Asm returns an assembly implementation of SHA3-224 if available,
14 | // otherwise it returns nil.
15 | func new224Asm() hash.Hash { return nil }
16 |
17 | // new256Asm returns an assembly implementation of SHA3-256 if available,
18 | // otherwise it returns nil.
19 | func new256Asm() hash.Hash { return nil }
20 |
21 | // new384Asm returns an assembly implementation of SHA3-384 if available,
22 | // otherwise it returns nil.
23 | func new384Asm() hash.Hash { return nil }
24 |
25 | // new512Asm returns an assembly implementation of SHA3-512 if available,
26 | // otherwise it returns nil.
27 | func new512Asm() hash.Hash { return nil }
28 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/keccakf_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build amd64,!appengine,!gccgo
6 |
7 | package sha3
8 |
9 | // This function is implemented in keccakf_amd64.s.
10 |
11 | //go:noescape
12 |
13 | func keccakF1600(a *[25]uint64)
14 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build go1.4
6 |
7 | package sha3
8 |
9 | import (
10 | "crypto"
11 | )
12 |
13 | func init() {
14 | crypto.RegisterHash(crypto.SHA3_224, New224)
15 | crypto.RegisterHash(crypto.SHA3_256, New256)
16 | crypto.RegisterHash(crypto.SHA3_384, New384)
17 | crypto.RegisterHash(crypto.SHA3_512, New512)
18 | }
19 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/shake_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //+build gccgo appengine !s390x
6 |
7 | package sha3
8 |
9 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
10 | // otherwise it returns nil.
11 | func newShake128Asm() ShakeHash {
12 | return nil
13 | }
14 |
15 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
16 | // otherwise it returns nil.
17 | func newShake256Asm() ShakeHash {
18 | return nil
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/testdata/keccakKats.json.deflate
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/xor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build !amd64,!386,!ppc64le appengine
6 |
7 | package sha3
8 |
9 | var (
10 | xorIn = xorInGeneric
11 | copyOut = copyOutGeneric
12 | xorInUnaligned = xorInGeneric
13 | copyOutUnaligned = copyOutGeneric
14 | )
15 |
16 | const xorImplementationUnaligned = "generic"
17 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/sha3/xor_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package sha3
6 |
7 | import "encoding/binary"
8 |
9 | // xorInGeneric xors the bytes in buf into the state; it
10 | // makes no non-portable assumptions about memory layout
11 | // or alignment.
12 | func xorInGeneric(d *state, buf []byte) {
13 | n := len(buf) / 8
14 |
15 | for i := 0; i < n; i++ {
16 | a := binary.LittleEndian.Uint64(buf)
17 | d.a[i] ^= a
18 | buf = buf[8:]
19 | }
20 | }
21 |
22 | // copyOutGeneric copies ulint64s to a byte buffer.
23 | func copyOutGeneric(d *state, b []byte) {
24 | for i := 0; len(b) >= 8; i++ {
25 | binary.LittleEndian.PutUint64(b, d.a[i])
26 | b = b[8:]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2011 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package ssh implements an SSH client and server.
7 |
8 | SSH is a transport security protocol, an authentication protocol and a
9 | family of application protocols. The most typical application level
10 | protocol is a remote shell and this is specifically implemented. However,
11 | the multiplexed nature of SSH is exposed to users that wish to support
12 | others.
13 |
14 | References:
15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
17 |
18 | This package does not fall under the stability promise of the Go language itself,
19 | so its API may be changed when pressing needs arise.
20 | */
21 | package ssh // import "golang.org/x/crypto/ssh"
22 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/tcpip_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package ssh
6 |
7 | import (
8 | "testing"
9 | )
10 |
11 | func TestAutoPortListenBroken(t *testing.T) {
12 | broken := "SSH-2.0-OpenSSH_5.9hh11"
13 | works := "SSH-2.0-OpenSSH_6.1"
14 | if !isBrokenOpenSSHVersion(broken) {
15 | t.Errorf("version %q not marked as broken", broken)
16 | }
17 | if isBrokenOpenSSHVersion(works) {
18 | t.Errorf("version %q marked as broken", works)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/terminal/util_bsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd netbsd openbsd
6 |
7 | package terminal
8 |
9 | import "golang.org/x/sys/unix"
10 |
11 | const ioctlReadTermios = unix.TIOCGETA
12 | const ioctlWriteTermios = unix.TIOCSETA
13 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/terminal/util_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package terminal
6 |
7 | import "golang.org/x/sys/unix"
8 |
9 | const ioctlReadTermios = unix.TCGETS
10 | const ioctlWriteTermios = unix.TCSETS
11 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/test/banner_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build darwin dragonfly freebsd linux netbsd openbsd
6 |
7 | package test
8 |
9 | import (
10 | "testing"
11 | )
12 |
13 | func TestBannerCallbackAgainstOpenSSH(t *testing.T) {
14 | server := newServer(t)
15 | defer server.Shutdown()
16 |
17 | clientConf := clientConfig()
18 |
19 | var receivedBanner string
20 | clientConf.BannerCallback = func(message string) error {
21 | receivedBanner = message
22 | return nil
23 | }
24 |
25 | conn := server.Dial(clientConf)
26 | defer conn.Close()
27 |
28 | expected := "Server Banner"
29 | if receivedBanner != expected {
30 | t.Fatalf("got %v; want %v", receivedBanner, expected)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/test/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package test contains integration tests for the
6 | // golang.org/x/crypto/ssh package.
7 | package test // import "golang.org/x/crypto/ssh/test"
8 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/golang.org/x/crypto/ssh/testdata/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // This package contains test data shared between the various subpackages of
6 | // the golang.org/x/crypto/ssh package. Under no circumstance should
7 | // this data be used for production code.
8 | package testdata // import "golang.org/x/crypto/ssh/testdata"
9 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | "github.com/boltdb/bolt"
7 | )
8 | /*
9 | 创建一个区块链的迭代器
10 | */
11 | type BlockchainIterator struct{
12 | currentHash []byte
13 | db *bolt.DB
14 | }
15 |
16 | //区块链迭代
17 | func (bci *BlockchainIterator) Next() *Block{
18 | var block *Block
19 | err := bci.db.View(func(tx *bolt.Tx) error{
20 | bucket := tx.Bucket([]byte(blockTable))
21 | blockBytes := bucket.Get( bci.currentHash )
22 | block = UnSerializeBlock(blockBytes)
23 | return nil
24 | })
25 | if err != nil {
26 | fmt.Println(".......hell")
27 | log.Panic(err)
28 | }
29 | //更新当前迭代器
30 | bci.currentHash = block.PrevBlockHash
31 | return block
32 | }
33 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func (cli *CLI) createBlockchain(address string){
8 | bc := CreateBlockChain(address)
9 | defer bc.db.Close()
10 | fmt.Println("Done !")
11 | }
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/cli_mine.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func (cli *CLI) Mine() {
4 | //创建区块链实例
5 | bc := NewBlockchain()
6 | //创建交易1
7 | txIn := TXInput{[]byte("11111111111"),0,[]byte("1EEdwyuhhNXyYCheqibbTDnZygZD4ypiop"),[]byte("pubkey")}
8 | txOut := TXOutput{20,[]byte("1NBP1H3VMzPKNx6Lknk2pL7dFJTUQswC5n")}
9 | txOne := &Transaction{[]byte("22222222"), []TXInput{txIn},[]TXOutput{txOut}}
10 | bc.MineBlock([]*Transaction{txOne})
11 | //创建交易2
12 | txIn = TXInput{[]byte("11111111111"),0,[]byte("1EEdwyuhhNXyYCheqibbTDnZygZD4ypiop"),[]byte("pubkey")}
13 | txOut = TXOutput{10,[]byte("1NBP1H3VMzPKNx6Lknk2pL7dFJTUQswC5n")}
14 | txSec := &Transaction{[]byte("22222222"),[]TXInput{txIn},[]TXOutput{txOut}}
15 | bc.MineBlock([]*Transaction{txSec})
16 | }
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/cli_printblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "strconv"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) printBlockChain() {
9 | bc := NewBlockchain()
10 | it := bc.Iterator()
11 | for {
12 | block := it.Next()
13 | fmt.Printf("============ Block %x ============\n", block.Hash)
14 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
15 | pow := NewProofOfWork(block)
16 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
17 |
18 | if len(block.PrevBlockHash) == 0 {
19 | break
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 |
4 | type TXInput struct{
5 | Txid []byte
6 | Vout int
7 | Signature []byte
8 | PubKey []byte
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type TXOutput struct {
4 | Value int
5 | PubKeyHash []byte
6 | }
--------------------------------------------------------------------------------
/代币底层实现/04.区块链数据结构的实现-2/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "github.com/boltdb/bolt"
6 | )
7 | /*
8 | 创建一个区块链的迭代器
9 | */
10 | type BlockchainIterator struct{
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | //区块链迭代
16 | func (bci *BlockchainIterator) Next() *Block{
17 | var block *Block
18 | err := bci.db.View(func(tx *bolt.Tx) error{
19 | bucket := tx.Bucket([]byte(blockTable))
20 | blockBytes := bucket.Get( bci.currentHash )
21 | block = UnSerializeBlock(blockBytes)
22 | return nil
23 | })
24 | if err != nil {
25 | log.Panic(err)
26 | }
27 | //更新当前迭代器
28 | bci.currentHash = block.PrevBlockHash
29 | return block
30 | }
31 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address string){
9 | //判断当前钱包地址是否有效
10 | if !ValidateAddress([]byte(address)) {
11 | log.Panic("错误的地址:",address)
12 | }
13 | bc := CreateBlockChain(address)
14 | defer bc.db.Close()
15 |
16 | //创建utxo_set
17 | u := UTXOSet{bc}
18 | u.Reindex()
19 |
20 | fmt.Println("Done !")
21 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address string) {
9 | if !ValidateAddress([]byte(address)) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain()
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_printblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "strconv"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) printBlockChain() {
9 | bc := NewBlockchain()
10 | it := bc.Iterator()
11 | for {
12 | block := it.Next()
13 | fmt.Printf("============ Block %x ============\n", block.Hash)
14 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
15 | pow := NewProofOfWork(block)
16 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
17 |
18 | if len(block.PrevBlockHash) == 0 {
19 | break
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 | import (
3 | "fmt"
4 | "log"
5 | )
6 | func (cli *CLI) Send(from,to string,amout int){
7 | if !ValidateAddress([]byte(from)) {
8 | log.Panic("ERROR: 发送人的地址错误")
9 | }
10 | if !ValidateAddress([]byte(to)) {
11 | log.Panic("ERROR: 接收人的地址错误")
12 | }
13 |
14 | //创建区块链
15 | bc := NewBlockchain()
16 | defer bc.db.Close()
17 | //创建utxo集合
18 | utxo := UTXOSet{bc}
19 | transaction := NewUTXOTransaction(from,to,amout,&utxo)
20 | cbtx := NewCoinbaseTX(from,"")
21 | txs := []*Transaction{transaction,cbtx}
22 | //挖矿
23 | block := bc.MineBlock(txs)
24 | utxo.Update(block)
25 | //utxo.Reindex()
26 | fmt.Println("Success~!")
27 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | )
6 |
7 | //交易输入
8 | type TXInput struct{
9 | Txid []byte
10 | Vout int
11 | Signature []byte
12 | PubKey []byte
13 | }
14 |
15 | //消费一笔输出时进行检查
16 | func (in *TXInput) UsesKey(PubKeyHash []byte) bool{
17 | PubKeyHash160 := HashPubKey(in.PubKey)
18 | return bytes.Compare(PubKeyHash160,PubKeyHash) == 0
19 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | )
6 |
7 | type TXOutput struct {
8 | Value int
9 | PubKeyHash []byte
10 | }
11 |
12 | //创建输出
13 | func NewTXOutput(value int , address string) *TXOutput{
14 | out := &TXOutput{value,nil}
15 | out.Lock([]byte(address))
16 | return out
17 | }
18 |
19 | //锁定地址
20 | func (out *TXOutput) Lock(address []byte){
21 | pubKey160 := Base58Decode(address)
22 | pubKey160 = pubKey160[1:len(pubKey160)-4]
23 | out.PubKeyHash = pubKey160
24 | }
25 |
26 | //解锁地址
27 | func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool {
28 | return bytes.Compare(out.PubKeyHash,pubKeyHash) == 0
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/transaction_outputs.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "encoding/gob"
6 | "bytes"
7 | )
8 |
9 | type TXOutputs struct{
10 | Outputs []TXOutput
11 | }
12 | //序列化交易输出集合
13 | func (outs TXOutputs) Serialize() []byte{
14 | var buffer bytes.Buffer
15 | encoder := gob.NewEncoder(&buffer)
16 | err := encoder.Encode(outs)
17 | if err != nil {
18 | log.Panic(err)
19 | }
20 | return buffer.Bytes()
21 | }
22 | //反序列化交易输出集合
23 | func UnSerializeTXOutputs(txOutputsBytes []byte) TXOutputs{
24 | var outputs TXOutputs
25 | decoder := gob.NewDecoder( bytes.NewReader(txOutputsBytes) )
26 | err := decoder.Decode(&outputs)
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 | return outputs
31 | }
--------------------------------------------------------------------------------
/代币底层实现/05.实现UTXO交易/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/blc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/06.MerkleTree-梅克尔树/src/blc
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/blockchain.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/06.MerkleTree-梅克尔树/src/blockchain.db
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "github.com/boltdb/bolt"
6 | )
7 | /*
8 | 创建一个区块链的迭代器
9 | */
10 | type BlockchainIterator struct{
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | //区块链迭代
16 | func (bci *BlockchainIterator) Next() *Block{
17 | var block *Block
18 | err := bci.db.View(func(tx *bolt.Tx) error{
19 | bucket := tx.Bucket([]byte(blockTable))
20 | blockBytes := bucket.Get( bci.currentHash )
21 | block = UnSerializeBlock(blockBytes)
22 | return nil
23 | })
24 | if err != nil {
25 | log.Panic(err)
26 | }
27 | //更新当前迭代器
28 | bci.currentHash = block.PrevBlockHash
29 | return block
30 | }
31 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address string){
9 | //判断当前钱包地址是否有效
10 | if !ValidateAddress([]byte(address)) {
11 | log.Panic("错误的地址:",address)
12 | }
13 | bc := CreateBlockChain(address)
14 | defer bc.db.Close()
15 |
16 | //创建utxo_set
17 | u := UTXOSet{bc}
18 | u.Reindex()
19 |
20 | fmt.Println("Done !")
21 | }
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address string) {
9 | if !ValidateAddress([]byte(address)) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain()
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_printblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "strconv"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) printBlockChain() {
9 | bc := NewBlockchain()
10 | it := bc.Iterator()
11 | for {
12 | block := it.Next()
13 | fmt.Printf("============ Block %x ============\n", block.Hash)
14 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
15 | pow := NewProofOfWork(block)
16 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
17 |
18 | if len(block.PrevBlockHash) == 0 {
19 | break
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 | import (
3 | "fmt"
4 | "log"
5 | )
6 | func (cli *CLI) Send(from,to string,amout int){
7 | if !ValidateAddress([]byte(from)) {
8 | log.Panic("ERROR: 发送人的地址错误")
9 | }
10 | if !ValidateAddress([]byte(to)) {
11 | log.Panic("ERROR: 接收人的地址错误")
12 | }
13 |
14 | //创建区块链
15 | bc := NewBlockchain()
16 | defer bc.db.Close()
17 | //创建utxo集合
18 | utxo := UTXOSet{bc}
19 | transaction := NewUTXOTransaction(from,to,amout,&utxo)
20 | cbtx := NewCoinbaseTX(from,"")
21 | txs := []*Transaction{transaction,cbtx}
22 | //挖矿
23 | block := bc.MineBlock(txs)
24 | utxo.Update(block)
25 | //utxo.Reindex()
26 | fmt.Println("Success~!")
27 | }
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | //"bytes"
5 | )
6 |
7 | //交易输入
8 | type TXInput struct{
9 | Txid []byte
10 | Vout int
11 | Signature []byte
12 | PubKey []byte
13 | }
14 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | )
6 |
7 | type TXOutput struct {
8 | Value int
9 | PubKeyHash []byte
10 | }
11 |
12 | //创建输出
13 | func NewTXOutput(value int , address string) *TXOutput{
14 | out := &TXOutput{value,nil}
15 | out.Lock([]byte(address))
16 | return out
17 | }
18 |
19 | //锁定地址
20 | func (out *TXOutput) Lock(address []byte){
21 | pubKey160 := Base58Decode(address)
22 | pubKey160 = pubKey160[1:len(pubKey160)-4]
23 | out.PubKeyHash = pubKey160
24 | }
25 |
26 | //解锁地址
27 | func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool {
28 | return bytes.Compare(out.PubKeyHash,pubKeyHash) == 0
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/transaction_outputs.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "encoding/gob"
6 | "bytes"
7 | )
8 |
9 | type TXOutputs struct{
10 | Outputs []TXOutput
11 | }
12 | //序列化交易输出集合
13 | func (outs TXOutputs) Serialize() []byte{
14 | var buffer bytes.Buffer
15 | encoder := gob.NewEncoder(&buffer)
16 | err := encoder.Encode(outs)
17 | if err != nil {
18 | log.Panic(err)
19 | }
20 | return buffer.Bytes()
21 | }
22 | //反序列化交易输出集合
23 | func UnSerializeTXOutputs(txOutputsBytes []byte) TXOutputs{
24 | var outputs TXOutputs
25 | decoder := gob.NewDecoder( bytes.NewReader(txOutputsBytes) )
26 | err := decoder.Decode(&outputs)
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 | return outputs
31 | }
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/代币底层实现/06.MerkleTree-梅克尔树/src/wallets.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/代币底层实现/06.MerkleTree-梅克尔树/src/wallets.dat
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "github.com/boltdb/bolt"
6 | )
7 | /*
8 | 创建一个区块链的迭代器
9 | */
10 | type BlockchainIterator struct{
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | //区块链迭代
16 | func (bci *BlockchainIterator) Next() *Block{
17 | var block *Block
18 | err := bci.db.View(func(tx *bolt.Tx) error{
19 | bucket := tx.Bucket([]byte(blockTable))
20 | blockBytes := bucket.Get( bci.currentHash )
21 | block = UnSerializeBlock(blockBytes)
22 | return nil
23 | })
24 | if err != nil {
25 | log.Panic(err)
26 | }
27 | //更新当前迭代器
28 | bci.currentHash = block.PrevBlockHash
29 | return block
30 | }
31 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address string){
9 | //判断当前钱包地址是否有效
10 | if !ValidateAddress([]byte(address)) {
11 | log.Panic("错误的地址:",address)
12 | }
13 | bc := CreateBlockChain(address)
14 | defer bc.db.Close()
15 |
16 | //创建utxo_set
17 | u := UTXOSet{bc}
18 | u.Reindex()
19 |
20 | fmt.Println("Done !")
21 | }
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | //创建集合
7 | wallets, _ := NewWallets()
8 | //创建钱包并把钱包写入map[string]*Wallet字典中
9 | address := wallets.CreateWallet()
10 | //保持集合序列化数据到文件中
11 | wallets.SaveToFile()
12 |
13 | fmt.Printf("你创建的新钱包地址是: %s\n", address)
14 | }
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address string) {
9 | if !ValidateAddress([]byte(address)) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain()
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_listaddresses.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | //获取所有的钱包地址
14 | addresses := wallets.GetAddresses()
15 | //遍历输出
16 | for _, address := range addresses {
17 | fmt.Println(address)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_printblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "strconv"
5 | "fmt"
6 | )
7 |
8 | func (cli *CLI) printBlockChain() {
9 | bc := NewBlockchain()
10 | it := bc.Iterator()
11 | for {
12 | block := it.Next()
13 | fmt.Printf("============ Block %x ============\n", block.Hash)
14 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
15 | pow := NewProofOfWork(block)
16 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
17 |
18 | if len(block.PrevBlockHash) == 0 {
19 | break
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 | import (
3 | "fmt"
4 | "log"
5 | )
6 | func (cli *CLI) Send(from,to string,amout int){
7 | if !ValidateAddress([]byte(from)) {
8 | log.Panic("ERROR: 发送人的地址错误")
9 | }
10 | if !ValidateAddress([]byte(to)) {
11 | log.Panic("ERROR: 接收人的地址错误")
12 | }
13 |
14 | //创建区块链
15 | bc := NewBlockchain()
16 | defer bc.db.Close()
17 | //创建utxo集合
18 | utxo := UTXOSet{bc}
19 | transaction := NewUTXOTransaction(from,to,amout,&utxo)
20 | cbtx := NewCoinbaseTX(from,"")
21 | txs := []*Transaction{transaction,cbtx}
22 | //挖矿
23 | block := bc.MineBlock(txs)
24 | utxo.Update(block)
25 | //utxo.Reindex()
26 | fmt.Println("Success~!")
27 | }
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | //"bytes"
5 | )
6 |
7 | //交易输入
8 | type TXInput struct{
9 | Txid []byte
10 | Vout int
11 | Signature []byte
12 | PubKey []byte
13 | }
14 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | )
6 |
7 | type TXOutput struct {
8 | Value int
9 | PubKeyHash []byte
10 | }
11 |
12 | //创建输出
13 | func NewTXOutput(value int , address string) *TXOutput{
14 | out := &TXOutput{value,nil}
15 | out.Lock([]byte(address))
16 | return out
17 | }
18 |
19 | //锁定地址
20 | func (out *TXOutput) Lock(address []byte){
21 | pubKey160 := Base58Decode(address)
22 | pubKey160 = pubKey160[1:len(pubKey160)-4]
23 | out.PubKeyHash = pubKey160
24 | }
25 |
26 | //解锁地址
27 | func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool {
28 | return bytes.Compare(out.PubKeyHash,pubKeyHash) == 0
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/transaction_outputs.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "encoding/gob"
6 | "bytes"
7 | )
8 |
9 | type TXOutputs struct{
10 | Outputs []TXOutput
11 | }
12 | //序列化交易输出集合
13 | func (outs TXOutputs) Serialize() []byte{
14 | var buffer bytes.Buffer
15 | encoder := gob.NewEncoder(&buffer)
16 | err := encoder.Encode(outs)
17 | if err != nil {
18 | log.Panic(err)
19 | }
20 | return buffer.Bytes()
21 | }
22 | //反序列化交易输出集合
23 | func UnSerializeTXOutputs(txOutputsBytes []byte) TXOutputs{
24 | var outputs TXOutputs
25 | decoder := gob.NewDecoder( bytes.NewReader(txOutputsBytes) )
26 | err := decoder.Decode(&outputs)
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 | return outputs
31 | }
--------------------------------------------------------------------------------
/代币底层实现/07.数字签名的实现/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/以太坊/01.以太坊综述.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/01.以太坊综述.pptx
--------------------------------------------------------------------------------
/以太坊/DAICO.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/DAICO.doc
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/add-product-flow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/add-product-flow.png
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/centralized-vs-ipfs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/centralized-vs-ipfs.png
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/ebay-dapp-architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/ebay-dapp-architecture.png
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/ebay-dapp-frontend-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/ebay-dapp-frontend-1.png
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/ebay-list-item.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/ebay-list-item.png
--------------------------------------------------------------------------------
/以太坊/Ebay项目/images/list-product.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Ebay项目/images/list-product.png
--------------------------------------------------------------------------------
/以太坊/Truffle构建简单投票系统.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Truffle构建简单投票系统.doc
--------------------------------------------------------------------------------
/以太坊/Web3.js.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/Web3.js.pptx
--------------------------------------------------------------------------------
/以太坊/众筹DAPP/src/build/address.json:
--------------------------------------------------------------------------------
1 | "0x6EC4b31B9D3003ADb66769E3e60b946C3e7e8fe2"
--------------------------------------------------------------------------------
/以太坊/众筹DAPP/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './component/app';
4 | import * as serviceWorker from './serviceWorker';
5 |
6 | ReactDOM.render(, document.getElementById('root'));
7 | serviceWorker.unregister();
8 |
--------------------------------------------------------------------------------
/以太坊/众筹DAPP/src/libs/project.js:
--------------------------------------------------------------------------------
1 | import web3 from './web3';
2 | import Project from '../build/Project.json';
3 | /*
4 | const getContract = function(address){
5 | let contract = new web3.eth.Contract( JSON.parse(Project.interface),address )
6 | return contract
7 | }
8 | */
9 |
10 | const getContract = address => new web3.eth.Contract( JSON.parse(Project.interface),address )
11 |
12 | export default getContract;
--------------------------------------------------------------------------------
/以太坊/众筹DAPP/src/libs/projectList.js:
--------------------------------------------------------------------------------
1 | import web3 from './web3';
2 | //获取ABI
3 | import projectList from '../build/ProjectList.json';
4 | //获取合约的地址
5 | import address from '../build/address.json';
6 |
7 | let contract = new web3.eth.Contract(JSON.parse(projectList.interface) , address );
8 |
9 | export default contract;
--------------------------------------------------------------------------------
/以太坊/众筹DAPP/src/libs/web3.js:
--------------------------------------------------------------------------------
1 | import Web3 from 'web3';
2 |
3 |
4 | let web3;
5 | const rpcUrl = "http://localhost:8545";
6 | if( typeof window!=='undefined' && typeof window.web3 !== 'undefined' ){
7 | web3 = new Web3( window.web3.currentProvider )
8 | }else{
9 | web3 = new Web3( new Web3.providers.HttpProvider(rpcUrl) )
10 | }
11 |
12 | export default web3;
--------------------------------------------------------------------------------
/以太坊/基于Token投票系统的Dapp.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/基于Token投票系统的Dapp.doc
--------------------------------------------------------------------------------
/以太坊/简单投票系统的Dapp.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/以太坊/简单投票系统的Dapp.doc
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/01-基本原型/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Running"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/01-基本原型/src/block.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "crypto/sha256"
6 | "strconv"
7 | "time"
8 | )
9 |
10 | // Block keeps block headers
11 | type Block struct {
12 | Timestamp int64
13 | Data []byte
14 | PrevBlockHash []byte
15 | Hash []byte
16 | }
17 |
18 | // SetHash calculates and sets block hash
19 | func (b *Block) SetHash() {
20 | timestamp := []byte(strconv.FormatInt(b.Timestamp, 10))
21 | headers := bytes.Join([][]byte{b.PrevBlockHash, b.Data, timestamp}, []byte{})
22 | hash := sha256.Sum256(headers)
23 |
24 | b.Hash = hash[:]
25 | }
26 |
27 | // NewBlock creates and returns Block
28 | func NewBlock(data string, prevBlockHash []byte) *Block {
29 | block := &Block{time.Now().Unix(), []byte(data), prevBlockHash, []byte{}}
30 | block.SetHash()
31 | return block
32 | }
33 |
34 | // NewGenesisBlock creates and returns genesis Block
35 | func NewGenesisBlock() *Block {
36 | return NewBlock("Genesis Block", []byte{})
37 | }
38 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/01-基本原型/src/blockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Blockchain keeps a sequence of Blocks
4 | type Blockchain struct {
5 | blocks []*Block
6 | }
7 |
8 | // AddBlock saves provided data as a block in the blockchain
9 | func (bc *Blockchain) AddBlock(data string) {
10 | prevBlock := bc.blocks[len(bc.blocks)-1]
11 | newBlock := NewBlock(data, prevBlock.Hash)
12 | bc.blocks = append(bc.blocks, newBlock)
13 | }
14 |
15 | // NewBlockchain creates a new Blockchain with genesis Block
16 | func NewBlockchain() *Blockchain {
17 | return &Blockchain{[]*Block{NewGenesisBlock()}}
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/01-基本原型/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | bc := NewBlockchain()
9 |
10 | bc.AddBlock("Send 1 BTC to Ivan")
11 | bc.AddBlock("Send 2 more BTC to Ivan")
12 |
13 | for _, block := range bc.blocks {
14 | fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
15 | fmt.Printf("Data: %s\n", block.Data)
16 | fmt.Printf("Hash: %x\n", block.Hash)
17 | fmt.Println()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/02-工作量证明/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Run"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/02-工作量证明/src/block.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | // Block keeps block headers
8 | type Block struct {
9 | Timestamp int64
10 | Data []byte
11 | PrevBlockHash []byte
12 | Hash []byte
13 | Nonce int
14 | }
15 |
16 | // NewBlock creates and returns Block
17 | func NewBlock(data string, prevBlockHash []byte) *Block {
18 | block := &Block{time.Now().Unix(), []byte(data), prevBlockHash, []byte{}, 0}
19 | pow := NewProofOfWork(block)
20 | nonce, hash := pow.Run()
21 |
22 | block.Hash = hash[:]
23 | block.Nonce = nonce
24 |
25 | return block
26 | }
27 |
28 | // NewGenesisBlock creates and returns genesis Block
29 | func NewGenesisBlock() *Block {
30 | return NewBlock("Genesis Block", []byte{})
31 | }
32 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/02-工作量证明/src/blockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Blockchain keeps a sequence of Blocks
4 | type Blockchain struct {
5 | blocks []*Block
6 | }
7 |
8 | // AddBlock saves provided data as a block in the blockchain
9 | func (bc *Blockchain) AddBlock(data string) {
10 | prevBlock := bc.blocks[len(bc.blocks)-1]
11 | newBlock := NewBlock(data, prevBlock.Hash)
12 | bc.blocks = append(bc.blocks, newBlock)
13 | }
14 |
15 | // NewBlockchain creates a new Blockchain with genesis Block
16 | func NewBlockchain() *Blockchain {
17 | return &Blockchain{[]*Block{NewGenesisBlock()}}
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/02-工作量证明/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | func main() {
9 | bc := NewBlockchain()
10 |
11 | bc.AddBlock("Send 1 BTC to Ivan")
12 | bc.AddBlock("Send 2 more BTC to Ivan")
13 |
14 | for _, block := range bc.blocks {
15 | fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
16 | fmt.Printf("Data: %s\n", block.Data)
17 | fmt.Printf("Hash: %x\n", block.Hash)
18 | pow := NewProofOfWork(block)
19 | fmt.Printf("PoW: %s\n", strconv.FormatBool(pow.Validate()))
20 | fmt.Println()
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/02-工作量证明/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/.idea/src.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build test
4 |
5 | build: deps
6 | @echo "====> Go build"
7 | @go build -o $(BINARY)
8 |
9 | deps:
10 | @go get -u github.com/boltdb/bolt
11 |
12 | test:
13 | ./$(BINARY) printchain
14 | ./$(BINARY) addblock -data "Send 1 BTC to Ivan"
15 | ./$(BINARY) addblock -data "Pay 0.31337 BTC for a coffee"
16 | ./$(BINARY) printchain
17 |
18 | .PHONY: build deps test
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | bc := NewBlockchain()
5 | defer bc.db.Close()
6 |
7 | cli := CLI{bc}
8 | cli.Run()
9 | }
10 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/03-持久化和CLI/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/04-交易(1)实现UTXO机制/img/blockchain-info-tx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/比特币权威教材/Golang实现比特币/04-交易(1)实现UTXO机制/img/blockchain-info-tx.png
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/04-交易(1)实现UTXO机制/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | build:
4 | @echo "====> Go build"
5 | @go build -o $(BINARY)
6 |
7 | .PHONY: build
8 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/04-交易(1)实现UTXO机制/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
7 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/04-交易(1)实现UTXO机制/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Running"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/boltdb/bolt"
7 | )
8 |
9 | // BlockchainIterator is used to iterate over blockchain blocks
10 | type BlockchainIterator struct {
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | // Next returns next block starting from the tip
16 | func (i *BlockchainIterator) Next() *Block {
17 | var block *Block
18 |
19 | err := i.db.View(func(tx *bolt.Tx) error {
20 | b := tx.Bucket([]byte(blocksBucket))
21 | encodedBlock := b.Get(i.currentHash)
22 | block = DeserializeBlock(encodedBlock)
23 |
24 | return nil
25 | })
26 |
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 |
31 | i.currentHash = block.PrevBlockHash
32 |
33 | return block
34 | }
35 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := CreateBlockchain(address)
13 | bc.db.Close()
14 | fmt.Println("Done!")
15 | }
16 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | wallets, _ := NewWallets()
7 | address := wallets.CreateWallet()
8 | wallets.SaveToFile()
9 |
10 | fmt.Printf("Your new address: %s\n", address)
11 | }
12 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain(address)
13 | defer bc.db.Close()
14 |
15 | balance := 0
16 | pubKeyHash := Base58Decode([]byte(address))
17 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
18 | UTXOs := bc.FindUTXO(pubKeyHash)
19 |
20 | for _, out := range UTXOs {
21 | balance += out.Value
22 | }
23 |
24 | fmt.Printf("Balance of '%s': %d\n", address, balance)
25 | }
26 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_listaddress.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | addresses := wallets.GetAddresses()
14 |
15 | for _, address := range addresses {
16 | fmt.Println(address)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_printchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | func (cli *CLI) printChain() {
9 | bc := NewBlockchain("")
10 | defer bc.db.Close()
11 |
12 | bci := bc.Iterator()
13 |
14 | for {
15 | block := bci.Next()
16 |
17 | fmt.Printf("============ Block %x ============\n", block.Hash)
18 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
19 | pow := NewProofOfWork(block)
20 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
21 | for _, tx := range block.Transactions {
22 | fmt.Println(tx)
23 | }
24 | fmt.Printf("\n\n")
25 |
26 | if len(block.PrevBlockHash) == 0 {
27 | break
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) send(from, to string, amount int) {
9 | if !ValidateAddress(from) {
10 | log.Panic("ERROR: Sender address is not valid")
11 | }
12 | if !ValidateAddress(to) {
13 | log.Panic("ERROR: Recipient address is not valid")
14 | }
15 |
16 | bc := NewBlockchain(from)
17 | defer bc.db.Close()
18 |
19 | tx := NewUTXOTransaction(from, to, amount, bc)
20 | bc.MineBlock([]*Transaction{tx})
21 | fmt.Println("Success!")
22 | }
23 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
7 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "bytes"
4 |
5 | // TXInput represents a transaction input
6 | type TXInput struct {
7 | Txid []byte
8 | Vout int
9 | Signature []byte
10 | PubKey []byte
11 | }
12 |
13 | // UsesKey checks whether the address initiated the transaction
14 | func (in *TXInput) UsesKey(pubKeyHash []byte) bool {
15 | lockingHash := HashPubKey(in.PubKey)
16 |
17 | return bytes.Compare(lockingHash, pubKeyHash) == 0
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/transaction_output.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "bytes"
4 |
5 | // TXOutput represents a transaction output
6 | type TXOutput struct {
7 | Value int
8 | PubKeyHash []byte
9 | }
10 |
11 | // Lock signs the output
12 | func (out *TXOutput) Lock(address []byte) {
13 | pubKeyHash := Base58Decode(address)
14 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
15 | out.PubKeyHash = pubKeyHash
16 | }
17 |
18 | // IsLockedWithKey checks if the output can be used by the owner of the pubkey
19 | func (out *TXOutput) IsLockedWithKey(pubKeyHash []byte) bool {
20 | return bytes.Compare(out.PubKeyHash, pubKeyHash) == 0
21 | }
22 |
23 | // NewTXOutput create a new TXOutput
24 | func NewTXOutput(value int, address string) *TXOutput {
25 | txo := &TXOutput{value, nil}
26 | txo.Lock([]byte(address))
27 |
28 | return txo
29 | }
30 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/05-比特币地址和数字签名/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Running"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/boltdb/bolt"
7 | )
8 |
9 | // BlockchainIterator is used to iterate over blockchain blocks
10 | type BlockchainIterator struct {
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | // Next returns next block starting from the tip
16 | func (i *BlockchainIterator) Next() *Block {
17 | var block *Block
18 |
19 | err := i.db.View(func(tx *bolt.Tx) error {
20 | b := tx.Bucket([]byte(blocksBucket))
21 | encodedBlock := b.Get(i.currentHash)
22 | block = DeserializeBlock(encodedBlock)
23 |
24 | return nil
25 | })
26 |
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 |
31 | i.currentHash = block.PrevBlockHash
32 |
33 | return block
34 | }
35 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := CreateBlockchain(address)
13 | defer bc.db.Close()
14 |
15 | UTXOSet := UTXOSet{bc}
16 | UTXOSet.Reindex()
17 |
18 | fmt.Println("Done!")
19 | }
20 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet() {
6 | wallets, _ := NewWallets()
7 | address := wallets.CreateWallet()
8 | wallets.SaveToFile()
9 |
10 | fmt.Printf("Your new address: %s\n", address)
11 | }
12 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain()
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_listaddress.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses() {
9 | wallets, err := NewWallets()
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | addresses := wallets.GetAddresses()
14 |
15 | for _, address := range addresses {
16 | fmt.Println(address)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_printchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | func (cli *CLI) printChain() {
9 | bc := NewBlockchain()
10 | defer bc.db.Close()
11 |
12 | bci := bc.Iterator()
13 |
14 | for {
15 | block := bci.Next()
16 |
17 | fmt.Printf("============ Block %x ============\n", block.Hash)
18 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
19 | pow := NewProofOfWork(block)
20 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
21 | for _, tx := range block.Transactions {
22 | fmt.Println(tx)
23 | }
24 | fmt.Printf("\n\n")
25 |
26 | if len(block.PrevBlockHash) == 0 {
27 | break
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_reindexutxo.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) reindexUTXO() {
6 | bc := NewBlockchain()
7 | UTXOSet := UTXOSet{bc}
8 | UTXOSet.Reindex()
9 |
10 | count := UTXOSet.CountTransactions()
11 | fmt.Printf("Done! There are %d transactions in the UTXO set.\n", count)
12 | }
13 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) send(from, to string, amount int) {
9 | if !ValidateAddress(from) {
10 | log.Panic("ERROR: Sender address is not valid")
11 | }
12 | if !ValidateAddress(to) {
13 | log.Panic("ERROR: Recipient address is not valid")
14 | }
15 |
16 | bc := NewBlockchain()
17 | UTXOSet := UTXOSet{bc}
18 | defer bc.db.Close()
19 |
20 | tx := NewUTXOTransaction(from, to, amount, &UTXOSet)
21 | cbTx := NewCoinbaseTX(from, "")
22 | txs := []*Transaction{cbTx, tx}
23 |
24 | newBlock := bc.MineBlock(txs)
25 | UTXOSet.Update(newBlock)
26 | fmt.Println("Success!")
27 | }
28 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
7 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "bytes"
4 |
5 | // TXInput represents a transaction input
6 | type TXInput struct {
7 | Txid []byte
8 | Vout int
9 | Signature []byte
10 | PubKey []byte
11 | }
12 |
13 | // UsesKey checks whether the address initiated the transaction
14 | func (in *TXInput) UsesKey(pubKeyHash []byte) bool {
15 | lockingHash := HashPubKey(in.PubKey)
16 |
17 | return bytes.Compare(lockingHash, pubKeyHash) == 0
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/06-交易(2)优化交易和默克尔树/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Running"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/boltdb/bolt"
7 | )
8 |
9 | // BlockchainIterator is used to iterate over blockchain blocks
10 | type BlockchainIterator struct {
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | // Next returns next block starting from the tip
16 | func (i *BlockchainIterator) Next() *Block {
17 | var block *Block
18 |
19 | err := i.db.View(func(tx *bolt.Tx) error {
20 | b := tx.Bucket([]byte(blocksBucket))
21 | encodedBlock := b.Get(i.currentHash)
22 | block = DeserializeBlock(encodedBlock)
23 |
24 | return nil
25 | })
26 |
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 |
31 | i.currentHash = block.PrevBlockHash
32 |
33 | return block
34 | }
35 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address, nodeID string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := CreateBlockchain(address, nodeID)
13 | defer bc.db.Close()
14 |
15 | UTXOSet := UTXOSet{bc}
16 | UTXOSet.Reindex()
17 |
18 | fmt.Println("Done!")
19 | }
20 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet(nodeID string) {
6 | wallets, _ := NewWallets(nodeID)
7 | address := wallets.CreateWallet()
8 | wallets.SaveToFile(nodeID)
9 |
10 | fmt.Printf("Your new address: %s\n", address)
11 | }
12 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address, nodeID string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain(nodeID)
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_listaddress.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses(nodeID string) {
9 | wallets, err := NewWallets(nodeID)
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | addresses := wallets.GetAddresses()
14 |
15 | for _, address := range addresses {
16 | fmt.Println(address)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_printchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | func (cli *CLI) printChain(nodeID string) {
9 | bc := NewBlockchain(nodeID)
10 | defer bc.db.Close()
11 |
12 | bci := bc.Iterator()
13 |
14 | for {
15 | block := bci.Next()
16 |
17 | fmt.Printf("============ Block %x ============\n", block.Hash)
18 | fmt.Printf("Height: %d\n", block.Height)
19 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
20 | pow := NewProofOfWork(block)
21 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
22 | for _, tx := range block.Transactions {
23 | fmt.Println(tx)
24 | }
25 | fmt.Printf("\n\n")
26 |
27 | if len(block.PrevBlockHash) == 0 {
28 | break
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_reindexutxo.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) reindexUTXO(nodeID string) {
6 | bc := NewBlockchain(nodeID)
7 | UTXOSet := UTXOSet{bc}
8 | UTXOSet.Reindex()
9 |
10 | count := UTXOSet.CountTransactions()
11 | fmt.Printf("Done! There are %d transactions in the UTXO set.\n", count)
12 | }
13 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) send(from, to string, amount int, nodeID string, mineNow bool) {
9 | if !ValidateAddress(from) {
10 | log.Panic("ERROR: Sender address is not valid")
11 | }
12 | if !ValidateAddress(to) {
13 | log.Panic("ERROR: Recipient address is not valid")
14 | }
15 |
16 | bc := NewBlockchain(nodeID)
17 | UTXOSet := UTXOSet{bc}
18 | defer bc.db.Close()
19 |
20 | wallets, err := NewWallets(nodeID)
21 | if err != nil {
22 | log.Panic(err)
23 | }
24 | wallet := wallets.GetWallet(from)
25 |
26 | tx := NewUTXOTransaction(&wallet, to, amount, &UTXOSet)
27 |
28 | if mineNow {
29 | cbTx := NewCoinbaseTX(from, "")
30 | txs := []*Transaction{cbTx, tx}
31 |
32 | newBlock := bc.MineBlock(txs)
33 | UTXOSet.Update(newBlock)
34 | } else {
35 | sendTx(knownNodes[0], tx)
36 | }
37 |
38 | fmt.Println("Success!")
39 | }
40 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/cli_startnode.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) startNode(nodeID, minerAddress string) {
9 | fmt.Printf("Starting node %s\n", nodeID)
10 | if len(minerAddress) > 0 {
11 | if ValidateAddress(minerAddress) {
12 | fmt.Println("Mining is on. Address to receive rewards: ", minerAddress)
13 | } else {
14 | log.Panic("Wrong miner address!")
15 | }
16 | }
17 | StartServer(nodeID, minerAddress)
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
7 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "bytes"
4 |
5 | // TXInput represents a transaction input
6 | type TXInput struct {
7 | Txid []byte
8 | Vout int
9 | Signature []byte
10 | PubKey []byte
11 | }
12 |
13 | // UsesKey checks whether the address initiated the transaction
14 | func (in *TXInput) UsesKey(pubKeyHash []byte) bool {
15 | lockingHash := HashPubKey(in.PubKey)
16 |
17 | return bytes.Compare(lockingHash, pubKeyHash) == 0
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/07-网络/src/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/Makefile:
--------------------------------------------------------------------------------
1 | BINARY := blockchain
2 |
3 | all: build run
4 |
5 | build:
6 | @echo "==> Go build"
7 | @go build -o $(BINARY)
8 |
9 | run:
10 | @echo "==> Running"
11 | @./$(BINARY)
12 |
13 | .PHONY: build run
14 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/base58_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "log"
6 | "strings"
7 | "testing"
8 |
9 | "github.com/stretchr/testify/assert"
10 | )
11 |
12 | func TestBase58(t *testing.T) {
13 | rawHash := "00010966776006953D5567439E5E39F86A0D273BEED61967F6"
14 | hash, err := hex.DecodeString(rawHash)
15 | if err != nil {
16 | log.Fatal(err)
17 | }
18 |
19 | encoded := Base58Encode(hash)
20 | assert.Equal(t, "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM", string(encoded))
21 |
22 | decoded := Base58Decode([]byte("16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"))
23 | assert.Equal(t, strings.ToLower("00010966776006953D5567439E5E39F86A0D273BEED61967F6"), hex.EncodeToString(decoded))
24 | }
25 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/blockchain_iterator.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 |
6 | "github.com/boltdb/bolt"
7 | )
8 |
9 | // BlockchainIterator is used to iterate over blockchain blocks
10 | type BlockchainIterator struct {
11 | currentHash []byte
12 | db *bolt.DB
13 | }
14 |
15 | // Next returns next block starting from the tip
16 | func (i *BlockchainIterator) Next() *Block {
17 | var block *Block
18 |
19 | err := i.db.View(func(tx *bolt.Tx) error {
20 | b := tx.Bucket([]byte(blocksBucket))
21 | encodedBlock := b.Get(i.currentHash)
22 | block = DeserializeBlock(encodedBlock)
23 |
24 | return nil
25 | })
26 |
27 | if err != nil {
28 | log.Panic(err)
29 | }
30 |
31 | i.currentHash = block.PrevBlockHash
32 |
33 | return block
34 | }
35 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_createblockchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) createBlockchain(address, nodeID string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := CreateBlockchain(address, nodeID)
13 | defer bc.db.Close()
14 |
15 | UTXOSet := UTXOSet{bc}
16 | UTXOSet.Reindex()
17 |
18 | fmt.Println("Done!")
19 | }
20 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_createwallet.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) createWallet(nodeID string) {
6 | wallets, _ := NewWallets(nodeID)
7 | address := wallets.CreateWallet()
8 | wallets.SaveToFile(nodeID)
9 |
10 | fmt.Printf("Your new address: %s\n", address)
11 | }
12 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_getbalance.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) getBalance(address, nodeID string) {
9 | if !ValidateAddress(address) {
10 | log.Panic("ERROR: Address is not valid")
11 | }
12 | bc := NewBlockchain(nodeID)
13 | UTXOSet := UTXOSet{bc}
14 | defer bc.db.Close()
15 |
16 | balance := 0
17 | pubKeyHash := Base58Decode([]byte(address))
18 | pubKeyHash = pubKeyHash[1 : len(pubKeyHash)-4]
19 | UTXOs := UTXOSet.FindUTXO(pubKeyHash)
20 |
21 | for _, out := range UTXOs {
22 | balance += out.Value
23 | }
24 |
25 | fmt.Printf("Balance of '%s': %d\n", address, balance)
26 | }
27 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_listaddress.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) listAddresses(nodeID string) {
9 | wallets, err := NewWallets(nodeID)
10 | if err != nil {
11 | log.Panic(err)
12 | }
13 | addresses := wallets.GetAddresses()
14 |
15 | for _, address := range addresses {
16 | fmt.Println(address)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_printchain.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | func (cli *CLI) printChain(nodeID string) {
9 | bc := NewBlockchain(nodeID)
10 | defer bc.db.Close()
11 |
12 | bci := bc.Iterator()
13 |
14 | for {
15 | block := bci.Next()
16 |
17 | fmt.Printf("============ Block %x ============\n", block.Hash)
18 | fmt.Printf("Height: %d\n", block.Height)
19 | fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
20 | pow := NewProofOfWork(block)
21 | fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
22 | for _, tx := range block.Transactions {
23 | fmt.Println(tx)
24 | }
25 | fmt.Printf("\n\n")
26 |
27 | if len(block.PrevBlockHash) == 0 {
28 | break
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_reindexutxo.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func (cli *CLI) reindexUTXO(nodeID string) {
6 | bc := NewBlockchain(nodeID)
7 | UTXOSet := UTXOSet{bc}
8 | UTXOSet.Reindex()
9 |
10 | count := UTXOSet.CountTransactions()
11 | fmt.Printf("Done! There are %d transactions in the UTXO set.\n", count)
12 | }
13 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_send.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) send(from, to string, amount int, nodeID string, mineNow bool) {
9 | if !ValidateAddress(from) {
10 | log.Panic("ERROR: Sender address is not valid")
11 | }
12 | if !ValidateAddress(to) {
13 | log.Panic("ERROR: Recipient address is not valid")
14 | }
15 |
16 | bc := NewBlockchain(nodeID)
17 | UTXOSet := UTXOSet{bc}
18 | defer bc.db.Close()
19 |
20 | wallets, err := NewWallets(nodeID)
21 | if err != nil {
22 | log.Panic(err)
23 | }
24 | wallet := wallets.GetWallet(from)
25 |
26 | tx := NewUTXOTransaction(&wallet, to, amount, &UTXOSet)
27 |
28 | if mineNow {
29 | cbTx := NewCoinbaseTX(from, "")
30 | txs := []*Transaction{cbTx, tx}
31 |
32 | newBlock := bc.MineBlock(txs)
33 | UTXOSet.Update(newBlock)
34 | } else {
35 | sendTx(knownNodes[0], tx)
36 | }
37 |
38 | fmt.Println("Success!")
39 | }
40 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/cli_startnode.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | )
7 |
8 | func (cli *CLI) startNode(nodeID, minerAddress string) {
9 | fmt.Printf("Starting node %s\n", nodeID)
10 | if len(minerAddress) > 0 {
11 | if ValidateAddress(minerAddress) {
12 | fmt.Println("Mining is on. Address to receive rewards: ", minerAddress)
13 | } else {
14 | log.Panic("Wrong miner address!")
15 | }
16 | }
17 | StartServer(nodeID, minerAddress)
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | cli := CLI{}
5 | cli.Run()
6 | }
7 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/transaction_input.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "bytes"
4 |
5 | // TXInput represents a transaction input
6 | type TXInput struct {
7 | Txid []byte
8 | Vout int
9 | Signature []byte
10 | PubKey []byte
11 | }
12 |
13 | // UsesKey checks whether the address initiated the transaction
14 | func (in *TXInput) UsesKey(pubKeyHash []byte) bool {
15 | lockingHash := HashPubKey(in.PubKey)
16 |
17 | return bytes.Compare(lockingHash, pubKeyHash) == 0
18 | }
19 |
--------------------------------------------------------------------------------
/比特币权威教材/Golang实现比特币/最终版代码/utils.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 | "log"
7 | )
8 |
9 | // IntToHex converts an int64 to a byte array
10 | func IntToHex(num int64) []byte {
11 | buff := new(bytes.Buffer)
12 | err := binary.Write(buff, binary.BigEndian, num)
13 | if err != nil {
14 | log.Panic(err)
15 | }
16 |
17 | return buff.Bytes()
18 | }
19 |
20 | // ReverseBytes reverses a byte array
21 | func ReverseBytes(data []byte) {
22 | for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
23 | data[i], data[j] = data[j], data[i]
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/code/hash_example.py:
--------------------------------------------------------------------------------
1 | # example of iterating a nonce in a hashing algorithm's input
2 |
3 | from __future__ import print_function
4 | import hashlib
5 |
6 | text = "I am Satoshi Nakamoto"
7 |
8 | # iterate nonce from 0 to 19
9 | for nonce in range(20):
10 |
11 | # add the nonce to the end of the text
12 | input_data = text + str(nonce)
13 |
14 | # calculate the SHA-256 hash of the input (text+nonce)
15 | hash_data = hashlib.sha256(input_data).hexdigest()
16 |
17 | # show the input and hash result
18 | print(input_data, '=>', hash_data)
19 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/code/max_money.py:
--------------------------------------------------------------------------------
1 | # Original block reward for miners was 50 BTC
2 | start_block_reward = 50
3 | # 210000 is around every 4 years with a 10 minute block interval
4 | reward_interval = 210000
5 |
6 |
7 | def max_money():
8 | # 50 BTC = 50 0000 0000 Satoshis
9 | current_reward = 50 * 10**8
10 | total = 0
11 | while current_reward > 0:
12 | total += reward_interval * current_reward
13 | current_reward /= 2
14 | return total
15 |
16 |
17 | print("Total BTC to ever be created:", max_money(), "Satoshis")
18 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/code/p2wpkh.js:
--------------------------------------------------------------------------------
1 | var btc = require('bitcore-lib')
2 | var oldAddress = btc.Address.fromString("1Ek9S3QNnutPV7GhtzR8Lr8yKPhxnUP8iw") // here's the old address
3 | var oldHash = oldAddress.hashBuffer
4 | var segwitP2PKH = Buffer.concat([new Buffer("0014","hex"), oldHash]) // 0x00 + 0x14 (pushdata 20 bytes) + old pubkeyhash
5 | var p2shHash = btc.crypto.Hash.sha256ripemd160(segwitP2PKH)
6 | var p2shAddress = btc.Address.fromScriptHash(p2shHash)
7 | var newAddress = p2shAddress.toString()
8 | // 36ghjA1KSAB1jDYD2RdiexEcY7r6XjmDQk
9 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/code/rpc_example.py:
--------------------------------------------------------------------------------
1 | from bitcoin.rpc import RawProxy
2 |
3 | # Create a connection to local Bitcoin Core node
4 | p = RawProxy()
5 |
6 | # Run the getblockchaininfo command, store the resulting data in info
7 | info = p.getblockchaininfo()
8 |
9 | # Retrieve the 'blocks' element from the info
10 | print(info['blocks'])
11 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/code/rpc_transaction.py:
--------------------------------------------------------------------------------
1 | from bitcoin.rpc import RawProxy
2 |
3 | p = RawProxy()
4 |
5 | # Alice's transaction ID
6 | txid = "0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2"
7 |
8 | # First, retrieve the raw transaction in hex
9 | raw_tx = p.getrawtransaction(txid)
10 |
11 | # Decode the transaction hex into a JSON object
12 | decoded_tx = p.decoderawtransaction(raw_tx)
13 |
14 | # Retrieve each of the outputs from the transaction
15 | for output in decoded_tx['vout']:
16 | print(output['scriptPubKey']['addresses'], output['value'])
17 |
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/images/kuozhan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/比特币权威教材/精通比特币/images/kuozhan.png
--------------------------------------------------------------------------------
/比特币权威教材/精通比特币/images/kuozhan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengjim520golang/blockchain-tutorial/f0b80600ca54400040803858ebd2df0eea2ba919/比特币权威教材/精通比特币/images/kuozhan1.png
--------------------------------------------------------------------------------