diff --git a/Cargo.lock b/Cargo.lock index 30375fe0e02c1..bd3871a672b94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,9 +161,9 @@ source = "git+https://github.com/chainx-org/bit-vec.git#ced2a13de722307d5c966aa8 [[package]] name = "bitcrypto" version = "0.1.0" -source = "git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050#8b2dab29c12d19bcd75f268deb01ff19cccd7050" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" dependencies = [ - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "siphasher 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", ] @@ -246,16 +246,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chain" version = "0.1.0" -source = "git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050#8b2dab29c12d19bcd75f268deb01ff19cccd7050" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" dependencies = [ - "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.4 (git+https://github.com/serde-rs/bytes)", - "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", ] @@ -265,7 +265,7 @@ version = "0.1.0" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "chainx-api 0.1.0", "chainx-consensus 0.1.0", "chainx-executor 0.1.0", @@ -286,7 +286,7 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "rhododendron 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -513,6 +513,14 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clippy" +version = "0.0.302" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -643,17 +651,19 @@ version = "0.1.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bit-vec 0.5.0 (git+https://github.com/chainx-org/bit-vec.git)", - "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", - "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "keys 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "merkle 0.1.0 (git+https://github.com/chainx-org/merkle.git)", "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "script 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", - "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "sr-io 0.1.0 (git+https://github.com/paritytech/substrate)", "sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", "sr-std 0.1.0 (git+https://github.com/paritytech/substrate)", @@ -847,6 +857,20 @@ dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "eth-secp256k1" +version = "0.5.7" +source = "git+https://github.com/chainx-org/rust-secp256k1#f28414e9fa6be765d414c245af881ad4b17a8926" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.302 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (git+https://github.com/rust-lang/libc)", + "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", +] + [[package]] name = "eth-secp256k1" version = "0.5.7" @@ -1226,6 +1250,22 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "keys" +version = "0.1.0" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" +dependencies = [ + "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "eth-secp256k1 0.5.7 (git+https://github.com/chainx-org/rust-secp256k1)", + "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec-derive 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", +] + [[package]] name = "kvdb" version = "0.1.0" @@ -1274,6 +1314,11 @@ name = "lazycell" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libc" +version = "0.2.43" +source = "git+https://github.com/rust-lang/libc#9c5e70ae306463a23ec02179ac2c9fe05c3fb44e" + [[package]] name = "libc" version = "0.2.43" @@ -1683,13 +1728,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merkle" version = "0.1.0" -source = "git+https://github.com/chainx-org/merkle.git#915e62e46ea3f21f2bddd98d4f90362400dc4204" +source = "git+https://github.com/chainx-org/merkle.git#2fe1c26c2d294d013821e3239c504c6eae59ac39" dependencies = [ "bit-vec 0.5.0 (git+https://github.com/chainx-org/bit-vec.git)", - "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "parity-codec 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", - "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", ] @@ -2035,7 +2080,7 @@ dependencies = [ [[package]] name = "primitives" version = "0.1.0" -source = "git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050#8b2dab29c12d19bcd75f268deb01ff19cccd7050" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2346,6 +2391,19 @@ name = "scopeguard" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "script" +version = "0.1.0" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" +dependencies = [ + "bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "keys 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", + "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", +] + [[package]] name = "security-framework" version = "0.1.16" @@ -2415,10 +2473,10 @@ dependencies = [ [[package]] name = "serialization" version = "0.1.0" -source = "git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050#8b2dab29c12d19bcd75f268deb01ff19cccd7050" +source = "git+https://github.com/chainx-org/bitcoin-rust#b5778f689a0845c3133f86131e61ff68a7dba398" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)", + "primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)", "sr-std 0.1.0 (git+https://github.com/chainx-org/sr-std)", ] @@ -3207,6 +3265,15 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "term" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termcolor" version = "1.0.4" @@ -3834,7 +3901,7 @@ dependencies = [ "checksum base64 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5032d51da2741729bfdaeb2664d9b8c6d9fd1e2b90715c660b6def36628499c2" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" "checksum bit-vec 0.5.0 (git+https://github.com/chainx-org/bit-vec.git)" = "" -"checksum bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)" = "" +"checksum bitcrypto 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" @@ -3847,10 +3914,11 @@ dependencies = [ "checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" -"checksum chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)" = "" +"checksum chain 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum chashmap 2.2.1 (git+https://github.com/redox-os/tfs)" = "" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum clippy 0.0.302 (registry+https://github.com/rust-lang/crates.io-index)" = "d911ee15579a3f50880d8c1d59ef6e79f9533127a3bd342462f5d584f5e8c294" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" @@ -3874,6 +3942,7 @@ dependencies = [ "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum environmental 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db746025e3ea695bfa0ae744dbacd5fcfc8db51b9760cf8bd0ab69708bb93c49" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" +"checksum eth-secp256k1 0.5.7 (git+https://github.com/chainx-org/rust-secp256k1)" = "" "checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" "checksum etrace 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f17311e68ea07046ee809b8513f6c259518bc10173681d98c21f8c3926f56f40" "checksum exit-future 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9aa7b56cef68c4182db7212dece19cc9f6e2916cf9412e57e6cea53ec02f316d" @@ -3916,12 +3985,14 @@ dependencies = [ "checksum jsonrpc-server-utils 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)" = "" "checksum jsonrpc-ws-server 9.0.0 (git+https://github.com/paritytech/jsonrpc.git)" = "" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum keys 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72ae89206cea31c32014b39d5a454b96135894221610dbfd19cf4d2d044fa546" "checksum kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "06cf755dc587839ba34d3cbe3f12b6ad55850fbcdfe67336157a021a1a5c43ae" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum lazycell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddba4c30a78328befecec92fc94970e53b3ae385827d28620f0f5bb2493081e0" +"checksum libc 0.2.43 (git+https://github.com/rust-lang/libc)" = "" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" "checksum libp2p 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=8111062f0177fd7423626f2db9560273644a4c4d)" = "" @@ -3991,7 +4062,7 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28ea5118e2f41bfbc974b28d88c07621befd1fa5d6ec23549be96302a1a59dd2" -"checksum primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)" = "" +"checksum primitives 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" @@ -4030,6 +4101,7 @@ dependencies = [ "checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56" "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum script 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332" "checksum security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "5421621e836278a0b139268f36eee0dc7e389b784dc3f79d8f11aabadf41bead" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" @@ -4038,7 +4110,7 @@ dependencies = [ "checksum serde_bytes 0.10.4 (git+https://github.com/serde-rs/bytes)" = "" "checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe" "checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce" -"checksum serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust?rev=8b2dab29c12d19bcd75f268deb01ff19cccd7050)" = "" +"checksum serialization 0.1.0 (git+https://github.com/chainx-org/bitcoin-rust)" = "" "checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c" "checksum sha1 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "171698ce4ec7cbb93babeb3190021b4d72e96ccb98e33d277ae4ea959d6f2d9e" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" @@ -4099,6 +4171,7 @@ dependencies = [ "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "55c1195ef8513f3273d55ff59fe5da6940287a0d7a98331254397f464833675b" +"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" diff --git a/Cargo.toml b/Cargo.toml index 05abd5cf3b311..4af7c66cc7f53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,8 +47,8 @@ slog = "^2" log = "0.3" # bitcoin-rust -primitives = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050" } -chain = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050" } +primitives = { git = "https://github.com/chainx-org/bitcoin-rust" } +chain = { git = "https://github.com/chainx-org/bitcoin-rust" } [workspace] members = [ diff --git a/cxrml/bridge/btc/Cargo.toml b/cxrml/bridge/btc/Cargo.toml index ff66c2f36acfc..80dba3559e1bc 100644 --- a/cxrml/bridge/btc/Cargo.toml +++ b/cxrml/bridge/btc/Cargo.toml @@ -21,10 +21,12 @@ srml-consensus = { git = "https://github.com/paritytech/substrate", default-feat srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false } # bitcoin-rust -chain = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050", default-features = false } -primitives = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050", default-features = false } -serialization = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050", default-features = false } -bitcrypto = { git = "https://github.com/chainx-org/bitcoin-rust", rev = "8b2dab29c12d19bcd75f268deb01ff19cccd7050", default-features = false } +chain = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } +primitives = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } +serialization = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } +bitcrypto = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } +script = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } +keys = { git = "https://github.com/chainx-org/bitcoin-rust", default-features = false } merkle = { git = "https://github.com/chainx-org/merkle.git", default-features = false } bit-vec = { git = "https://github.com/chainx-org/bit-vec.git", default-features = false } rustc-hex = { version = "2", optional = true } @@ -52,9 +54,11 @@ std=[ # bitcoin-rust "chain/std", + "keys/std", "primitives/std", "serialization/std", "bitcrypto/std", + "script/std", "merkle/std", "bit-vec/std", ] diff --git a/cxrml/bridge/btc/src/b58.rs b/cxrml/bridge/btc/src/b58.rs index 9be1e572e8f32..127cea4e11f77 100644 --- a/cxrml/bridge/btc/src/b58.rs +++ b/cxrml/bridge/btc/src/b58.rs @@ -25,7 +25,10 @@ static BASE58_DIGITS: [Option; 128] = [ pub fn from(data: Vec) -> Result, &'static str> { // 11/15 is just over log_256(58) - let mut scratch = vec![0u8; 1 + data.len() * 11 / 15]; + let mut scratch = Vec::new(); + for _i in 0..1 + data.len() * 11 / 15 { + scratch.push(0); + } // Build in base 256 for d58 in data.clone() { // Compute "X = X * 58 + next_digit" in base 256 @@ -34,7 +37,9 @@ pub fn from(data: Vec) -> Result, &'static str> { } let mut carry = match BASE58_DIGITS[d58 as usize] { Some(d58) => d58 as u32, - None => { return Err("BadByte"); } + None => { + return Err("BadByte"); + } }; for d256 in scratch.iter_mut().rev() { carry += *d256 as u32 * 58; @@ -45,9 +50,10 @@ pub fn from(data: Vec) -> Result, &'static str> { } // Copy leading zeroes directly - let mut ret: Vec = data.iter().take_while(|&x| *x == BASE58_CHARS[0]) - .map(|_| 0) - .collect(); + let mut ret: Vec = data.iter() + .take_while(|&x| *x == BASE58_CHARS[0]) + .map(|_| 0) + .collect(); // Copy rest of string ret.extend(scratch.into_iter().skip_while(|&x| x == 0)); Ok(ret) @@ -59,9 +65,33 @@ mod tests { #[test] fn test_from() { let s = String::from("mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b"); - let v = &[111, 41, 168, 159, 89, 51, 97, 179, 153, 104, 9, 74, - 184, 193, 251, 6, 131, 166, 121, 3, 1, 241, 112, 101, 146]; + let v = &[ + 111, + 41, + 168, + 159, + 89, + 51, + 97, + 179, + 153, + 104, + 9, + 74, + 184, + 193, + 251, + 6, + 131, + 166, + 121, + 3, + 1, + 241, + 112, + 101, + 146, + ]; assert_eq!(from(s.as_bytes().to_vec()).unwrap(), v); } } - diff --git a/cxrml/bridge/btc/src/blockchain.rs b/cxrml/bridge/btc/src/blockchain.rs index 3fb2dd6ad1639..2df8c91279294 100644 --- a/cxrml/bridge/btc/src/blockchain.rs +++ b/cxrml/bridge/btc/src/blockchain.rs @@ -10,11 +10,13 @@ use primitives::hash::H256; use chain::BlockHeader; use super::{Trait, -// OrphanIndexFor, + // OrphanIndexFor, BlockHeaderFor, BestIndex, - HeaderNumberFor, HashForNumber, - ParamsInfo, Params}; + HeaderNumberFor, + HashForNumber, + ParamsInfo, + Params}; use tx::{TxStorage, RollBack}; @@ -63,9 +65,7 @@ pub struct SideChainOrigin { #[derive(Clone)] pub enum BlockOrigin { KnownBlock, - CanonChain { - block_number: u32, - }, + CanonChain { block_number: u32 }, SideChain(SideChainOrigin), SideChainBecomingCanonChain(SideChainOrigin), } @@ -105,7 +105,7 @@ impl ChainErr { } } -pub struct Chain (PhantomData); +pub struct Chain(PhantomData); impl Chain { pub fn insert_best_header(header: BlockHeader) -> Result<(), ChainErr> { @@ -126,9 +126,7 @@ impl Chain { Ok(()) } // case 3: block has been added to the side branch without reorganization to this branch - BlockOrigin::SideChain(_origin) => { - Ok(()) - } + BlockOrigin::SideChain(_origin) => Ok(()), } } @@ -138,17 +136,24 @@ impl Chain { let best_bumber = best_index.number; //todo change unwrap - let (best_header, _): (BlockHeader, T::AccountId) = >::get(&best_hash).unwrap(); + let (best_header, _): (BlockHeader, T::AccountId) = >::get(&best_hash) + .unwrap(); let new_best_header = BestHeader { hash: best_header.previous_header_hash.clone(), - number: if best_bumber > 0 { best_bumber - 1 } else { - if best_header.previous_header_hash != Default::default() { return Err(ChainErr::DecanonizeMustZero); } + number: if best_bumber > 0 { + best_bumber - 1 + } else { + if best_header.previous_header_hash != Default::default() { + return Err(ChainErr::DecanonizeMustZero); + } 0 }, }; // remove related tx - TxStorage::::rollback_tx(&best_hash).map_err(|s| ChainErr::OtherErr(s))?; + TxStorage::::rollback_tx(&best_hash).map_err(|s| { + ChainErr::OtherErr(s) + })?; >::remove(&best_hash); // do not need to remove HashForNumber @@ -172,7 +177,9 @@ impl Chain { let new_best_header = BestHeader { hash: hash.clone(), number: if header.previous_header_hash == Default::default() { - if best_number != 0 { return Err(ChainErr::CanonizeMustZero); } + if best_number != 0 { + return Err(ChainErr::CanonizeMustZero); + } 0 } else { best_number + 1 @@ -212,14 +219,15 @@ impl Chain { fn block_origin(header: &BlockHeader) -> Result { let best_index: BestHeader = >::get(); // TODO change unwrap - let (best_header, _): (BlockHeader, T::AccountId) = >::get(&best_index.hash).unwrap(); + let (best_header, _): (BlockHeader, T::AccountId) = + >::get(&best_index.hash).unwrap(); if >::exists(header.hash()) { return Ok(BlockOrigin::KnownBlock); } if best_header.hash() == header.previous_header_hash { return Ok(BlockOrigin::CanonChain { - block_number: best_index.number + 1 + block_number: best_index.number + 1, }); } @@ -248,7 +256,8 @@ impl Chain { let origin = SideChainOrigin { ancestor: number, canonized_route: sidechain_route.into_iter().rev().collect(), - decanonized_route: (number + 1..best_index.number + 1).into_iter() + decanonized_route: (number + 1..best_index.number + 1) + .into_iter() .filter_map(|decanonized_bn| { let hash = >::get(decanonized_bn); if hash == Default::default() { diff --git a/cxrml/bridge/btc/src/keys.rs b/cxrml/bridge/btc/src/keys.rs deleted file mode 100644 index a63f885744821..0000000000000 --- a/cxrml/bridge/btc/src/keys.rs +++ /dev/null @@ -1,346 +0,0 @@ -// Copyright 2018 Chainpool - -#[cfg(feature = "std")] -use std::{fmt, str}; -#[cfg(feature = "std")] -use base58::{ToBase58, FromBase58}; -use hex::{ToHex, FromHex}; -use hash::{H520, H264, H256, H160}; -use bitcrypto::{dhash160, checksum}; -use codec::{Encode, Decode}; -use rstd::ops; -use script::script::ScriptAddress; - -/// 20 bytes long hash derived from public `ripemd160(sha256(public))` -pub type AddressHash = H160; -/// 32 bytes long secret key -pub type Secret = H256; -/// 32 bytes long signable message -pub type Message = H256; - -const NETWORK_ID: u32 = 1; - -#[cfg_attr(feature = "std", derive(Debug))] -#[derive(PartialEq, Clone, Copy, Encode, Decode)] -pub enum Network { - Mainnet = 0, - Testnet = 1, -} - -impl Default for Network { - fn default() -> Network { Network::Mainnet } -} - -#[cfg_attr(feature = "std", derive(Debug))] -#[derive(PartialEq, Clone, Copy, Encode, Decode)] -pub enum Type { - /// Pay to PubKey Hash - /// Common P2PKH which begin with the number 1, eg: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2. - /// https://bitcoin.org/en/glossary/p2pkh-address - P2PKH, - /// Pay to Script Hash - /// Newer P2SH type starting with the number 3, eg: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy. - /// https://bitcoin.org/en/glossary/p2sh-address - P2SH, -} - -impl Default for Type { - fn default() -> Type { Type::P2PKH } -} - -pub trait DisplayLayout { - type Target: ops::Deref; - - fn layout(&self) -> Self::Target; - - fn from_layout(data: &[u8]) -> Result where Self: Sized; -} - -#[cfg_attr(feature = "std", derive(Debug))] -#[derive(PartialEq, Clone, Encode, Decode, Default)] -pub struct Address { - /// The type of the address. - pub kind: Type, - /// The network of the address. - pub network: Network, - /// Public key hash. - pub hash: AddressHash, -} - -impl<'a> From<&'a ScriptAddress> for Address { - fn from(address: &'a ScriptAddress) -> Self { - let network = if NETWORK_ID == 1 { Network::Testnet } else { Network::Mainnet }; - Address { - kind: address.kind, - network: network, - hash: address.hash.clone(), - } - } -} - -pub struct AddressDisplayLayout([u8; 25]); - -impl ops::Deref for AddressDisplayLayout { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DisplayLayout for Address { - type Target = AddressDisplayLayout; - - fn layout(&self) -> Self::Target { - let mut result = [0u8; 25]; - - result[0] = match (self.network, self.kind) { - (Network::Mainnet, Type::P2PKH) => 0, - (Network::Mainnet, Type::P2SH) => 5, - (Network::Testnet, Type::P2PKH) => 111, - (Network::Testnet, Type::P2SH) => 196, - }; - - result[1..21].copy_from_slice(&*self.hash); - let cs = checksum(&result[0..21]); - result[21..25].copy_from_slice(&*cs); - AddressDisplayLayout(result) - } - - fn from_layout(data: &[u8]) -> Result where Self: Sized { - if data.len() != 25 { - return Err(Error::InvalidAddress); - } - - let cs = checksum(&data[0..21]); - if &data[21..] != &*cs { - return Err(Error::InvalidChecksum); - } - - let (network, kind) = match data[0] { - 0 => (Network::Mainnet, Type::P2PKH), - 5 => (Network::Mainnet, Type::P2SH), - 111 => (Network::Testnet, Type::P2PKH), - 196 => (Network::Testnet, Type::P2SH), - _ => return Err(Error::InvalidAddress), - }; - - let mut hash = AddressHash::default(); - hash.copy_from_slice(&data[1..21]); - - let address = Address { - kind: kind, - network: network, - hash: hash, - }; - - Ok(address) - } -} - -#[cfg(feature = "std")] -impl fmt::Display for Address { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.layout().to_base58().fmt(f) - } -} - -#[cfg(feature = "std")] -impl str::FromStr for Address { - type Err = Error; - - fn from_str(s: &str) -> Result where Self: Sized { - let hex = try!(s.from_base58().map_err(|_| Error::InvalidAddress)); - Address::from_layout(&hex) - } -} - -impl From<&'static str> for Address { - fn from(s: &'static str) -> Self { - s.parse().unwrap() - } -} - -#[cfg_attr(feature = "std", derive(Debug))] -#[derive(PartialEq)] -pub enum Error { - InvalidPublic, - InvalidSecret, - InvalidMessage, - InvalidSignature, - InvalidNetwork, - InvalidChecksum, - InvalidPrivate, - InvalidAddress, -} - -/// Secret public key -pub enum Public { - /// Normal version of public key - Normal(H520), - /// Compressed version of public key - Compressed(H264), -} - -impl Public { - pub fn from_slice(data: &[u8]) -> Result { - match data.len() { - 33 => { - let mut public = H264::default(); - public.copy_from_slice(data); - Ok(Public::Compressed(public)) - }, - 65 => { - let mut public = H520::default(); - public.copy_from_slice(data); - Ok(Public::Normal(public)) - }, - _ => Err(Error::InvalidPublic) - } - } - - pub fn address_hash(&self) -> AddressHash { - let public_key: &[u8] = self; - dhash160(public_key) - } -} - -impl ops::Deref for Public { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - match *self { - Public::Normal(ref hash) => &**hash, - Public::Compressed(ref hash) => &**hash, - } - } -} - -impl PartialEq for Public { - fn eq(&self, other: &Self) -> bool { - let s_slice: &[u8] = self; - let o_slice: &[u8] = other; - s_slice == o_slice - } -} - -#[derive(PartialEq)] -pub struct Signature(Vec); - -#[cfg(feature = "std")] -impl fmt::Debug for Signature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.to_hex::().fmt(f) - } -} - -#[cfg(feature = "std")] -impl fmt::Display for Signature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.to_hex::().fmt(f) - } -} - -impl ops::Deref for Signature { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -#[cfg(feature = "std")] -impl str::FromStr for Signature { - type Err = Error; - - fn from_str(s: &str) -> Result { - let vec = try!(s.from_hex().map_err(|_| Error::InvalidSignature)); - Ok(Signature(vec)) - } -} - -impl From<&'static str> for Signature { - fn from(s: &'static str) -> Self { - s.parse().unwrap() - } -} - -impl From> for Signature { - fn from(v: Vec) -> Self { - Signature(v) - } -} - -impl From for Vec { - fn from(s: Signature) -> Self { - s.0 - } -} - -impl<'a> From<&'a [u8]> for Signature { - fn from(v: &'a [u8]) -> Self { - Signature(v.to_vec()) - } -} - -#[derive(PartialEq)] -pub struct CompactSignature(H520); - -#[cfg(feature = "std")] -impl fmt::Debug for CompactSignature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(&self.0.to_hex::()) - } -} - -#[cfg(feature = "std")] -impl fmt::Display for CompactSignature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(&self.0.to_hex::()) - } -} - -impl ops::Deref for CompactSignature { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - &*self.0 - } -} - -#[cfg(feature = "std")] -impl str::FromStr for CompactSignature { - type Err = Error; - - fn from_str(s: &str) -> Result { - match s.parse() { - Ok(hash) => Ok(CompactSignature(hash)), - _ => Err(Error::InvalidSignature), - } - } -} - -impl From<&'static str> for CompactSignature { - fn from(s: &'static str) -> Self { - s.parse().unwrap() - } -} - -impl From for CompactSignature { - fn from(h: H520) -> Self { - CompactSignature(h) - } -} - -#[cfg(test)] -mod tests { - use super::Address; - use super::DisplayLayout; - - #[test] - fn test_layout() { - let v = &[111, 41, 168, 159, 89, 51, 97, 179, 153, 104, 9, 74, - 184, 193, 251, 6, 131, 166, 121, 3, 1, 241, 112, 101, 146]; - Address::from_layout(v).unwrap(); - } -} diff --git a/cxrml/bridge/btc/src/lib.rs b/cxrml/bridge/btc/src/lib.rs index f46bbb4f67e79..98634f97fe217 100644 --- a/cxrml/bridge/btc/src/lib.rs +++ b/cxrml/bridge/btc/src/lib.rs @@ -38,12 +38,14 @@ extern crate srml_balances as balances; extern crate srml_timestamp as timestamp; // bitcoin-rust -extern crate primitives; -extern crate chain; extern crate serialization as ser; +extern crate primitives; extern crate bitcrypto; -extern crate merkle; extern crate bit_vec; +extern crate script; +extern crate merkle; +extern crate chain; +extern crate keys; #[cfg(test)] mod tests; @@ -51,8 +53,6 @@ mod tests; mod verify_header; mod blockchain; mod tx; -mod keys; -mod script; mod b58; use codec::Decode; @@ -66,13 +66,13 @@ use system::ensure_signed; use ser::deserialize; use chain::{BlockHeader, Transaction as BTCTransaction}; -use primitives::{hash::H256, compact::Compact}; -use primitives::hash; +use primitives::hash::H256; +use primitives::compact::Compact; pub use blockchain::BestHeader; use blockchain::Chain; -use tx::{UTXO, validate_transaction, handle_input, handle_output}; +use tx::{UTXO, validate_transaction, handle_input, handle_output, handle_proposal}; pub use tx::RelayTx; @@ -123,8 +123,14 @@ pub struct Params { } impl Params { - pub fn new(max_bits: u32, block_max_future: u32, max_fork_route_preset: u32, - target_timespan_seconds: u32, target_spacing_seconds: u32, retargeting_factor: u32) -> Params { + pub fn new( + max_bits: u32, + block_max_future: u32, + max_fork_route_preset: u32, + target_timespan_seconds: u32, + target_spacing_seconds: u32, + retargeting_factor: u32, + ) -> Params { Params { max_bits: max_bits, block_max_future: block_max_future, @@ -156,14 +162,16 @@ pub enum TxType { } #[derive(PartialEq, Clone, Encode, Decode)] -pub struct Proposal { - proposer: Vec, - tx: BTCTransaction, - perfection: bool, +pub struct CandidateTx { + pub proposer: Vec, + pub tx: BTCTransaction, + pub perfection: bool, } impl Default for TxType { - fn default() -> Self { TxType::Deposit } + fn default() -> Self { + TxType::Deposit + } } decl_storage! { @@ -188,15 +196,19 @@ decl_storage! { // ===== // tx pub ReceiveAddress get(receive_address) config(): Option>; + pub RedeemScript get(redeem_script) config(): Option>; pub UTXOSet get(utxo_set): map u64 => UTXO; pub UTXOMaxIndex get(utxo_max_index) config(): u64; pub TxSet get(tx_set): map H256 => Option<(T::AccountId, keys::Address, TxType, u64, BTCTransaction)>; // Address, type, balance pub BlockTxids get(block_txids): map H256 => Vec; - pub AddressMap get(address_map): map keys::Address => T::AccountId; - pub TxProposal get(tx_proposal): map H256 => Option>; + pub AddressMap get(address_map): map keys::Address => Option; + pub TxProposal get(tx_proposal): Option>; // pub AccountMap get(account_map): map T::AccountId => keys::Address; + pub AccountsMaxIndex get(accounts_max_index) config(): u64; + pub AccountsSet get(accounts_set): map u64 => Option<(H256, keys::Address, T::AccountId, u32, TxType)>; + // ===== // others pub Fee get(fee) config(): T::Balance; @@ -234,7 +246,9 @@ impl Module { pub fn push_header(origin: T::Origin, header: Vec) -> Result { let from = ensure_signed(origin)?; // parse header - let header: BlockHeader = deserialize(header.as_slice()).map_err(|_| "can't deserialize the header vec")?; + let header: BlockHeader = deserialize(header.as_slice()).map_err( + |_| "can't deserialize the header vec", + )?; Self::process_header(header, &from)?; Ok(()) } @@ -242,7 +256,9 @@ impl Module { pub fn push_transaction(origin: T::Origin, tx: Vec) -> Result { let from = ensure_signed(origin)?; - let tx: RelayTx = Decode::decode(&mut tx.as_slice()).ok_or("parse RelayTx err")?; + let tx: RelayTx = Decode::decode(&mut tx.as_slice()).ok_or( + "parse RelayTx err", + )?; Self::process_tx(tx, &from)?; Ok(()) } @@ -250,7 +266,9 @@ impl Module { pub fn propose_transaction(origin: T::Origin, tx: Vec) -> Result { let from = ensure_signed(origin)?; - let tx: BTCTransaction = Decode::decode(&mut tx.as_slice()).ok_or("parse transaction err")?; + let tx: BTCTransaction = Decode::decode(&mut tx.as_slice()).ok_or( + "parse transaction err", + )?; Self::process_btc_tx(tx, &from)?; Ok(()) } @@ -266,11 +284,15 @@ impl Module { // orphan block check if >::exists(&header.previous_header_hash) == false { - return Err("can't find the prev header in ChainX, may be a orphan block"); + return Err( + "can't find the prev header in ChainX, may be a orphan block", + ); } // check { - let c = verify_header::HeaderVerifier::new::(&header).map_err(|e| e.info())?; + let c = verify_header::HeaderVerifier::new::(&header).map_err( + |e| e.info(), + )?; c.check::()?; } // insert valid header into storage @@ -282,7 +304,9 @@ impl Module { } pub fn process_tx(tx: RelayTx, who: &T::AccountId) -> Result { - let receive_address: Vec = if let Some(h) = >::get() { h } else { + let receive_address: Vec = if let Some(h) = >::get() { + h + } else { return Err("should set RECEIVE_address first"); }; @@ -293,16 +317,22 @@ impl Module { match tx_type { TxType::Withdraw => { handle_input::(&tx.raw, &tx.block_hash, &who, &receive_address); - }, + } _ => { - let _utxos = handle_output::(&tx.raw, &tx.block_hash, &who, &tx.previous_raw, &receive_address); - }, + let _utxos = handle_output::( + &tx.raw, + &tx.block_hash, + &who, + &tx.previous_raw, + &receive_address, + ); + } } Ok(()) } pub fn process_btc_tx(tx: BTCTransaction, who: &T::AccountId) -> Result { - Ok(()) + handle_proposal::(tx, who) } } diff --git a/cxrml/bridge/btc/src/script/error.rs b/cxrml/bridge/btc/src/script/error.rs deleted file mode 100644 index 7044e60a55794..0000000000000 --- a/cxrml/bridge/btc/src/script/error.rs +++ /dev/null @@ -1,137 +0,0 @@ -//! Interpreter errors - -#[cfg(feature = "std")] -use std::fmt; - -use super::Opcode; - -/// Interpreter errors -#[derive(Debug, PartialEq)] -pub enum Error { - Unknown, - EvalFalse, - ReturnOpcode, - - // Max sizes. - ScriptSize, - PushSize, - OpCount, - StackSize, - NumberOverflow, - NumberNotMinimallyEncoded, - SigCount, - PubkeyCount, - - // Failed verify operations - Verify, - EqualVerify, - CheckSigVerify, - NumEqualVerify, - - // Logical/Format/Canonical errors. - BadOpcode, - DisabledOpcode(Opcode), - InvalidStackOperation, - InvalidAltstackOperation, - UnbalancedConditional, - InvalidSplitRange, - InvalidBitwiseOperation, - DivisionByZero, - ImpossibleEncoding, - - // CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY - NegativeLocktime, - UnsatisfiedLocktime, - - // BIP62 - SignatureHashtype, - SignatureDer, - SignatureIllegalForkId, - SignatureMustUseForkId, - Minimaldata, - SignaturePushOnly, - SignatureHighS, - SignatureNullDummy, - PubkeyType, - Cleanstack, - - // Softfork safeness - DiscourageUpgradableNops, - DiscourageUpgradableWitnessProgram, - - // SegWit-related errors - WitnessProgramWrongLength, - WitnessProgramWitnessEmpty, - WitnessProgramMismatch, - WitnessMalleated, - WitnessMalleatedP2SH, - WitnessUnexpected, - WitnessPubKeyType, -} - -#[cfg(feature = "std")] -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Error::Unknown => "Unknown error".fmt(f), - Error::EvalFalse => "Script evaluated to false".fmt(f), - Error::ReturnOpcode => "Used return opcode".fmt(f), - - // Failed verify operations - Error::Verify => "Failed verify operation".fmt(f), - Error::EqualVerify => "Failed equal verify operation".fmt(f), - Error::CheckSigVerify => "Failed signature check".fmt(f), - Error::NumEqualVerify => "Failed num equal verify operation".fmt(f), - Error::SigCount => "Maximum number of signature exceeded".fmt(f), - Error::PubkeyCount => "Maximum number of pubkeys per multisig exceeded".fmt(f), - - // Max sizes. - Error::ScriptSize => "Script is too long".fmt(f), - Error::PushSize => "Pushing too many bytes".fmt(f), - Error::OpCount => "Script contains to many opcodes".fmt(f), - Error::StackSize => "Stack is too big".fmt(f), - Error::NumberOverflow => "Number overflow".fmt(f), - Error::NumberNotMinimallyEncoded => "Number not minimally encoded".fmt(f), - - // Logical/Format/Canonical errors. - Error::BadOpcode => "Bad Opcode".fmt(f), - Error::DisabledOpcode(ref opcode) => writeln!(f, "Disabled Opcode: {:?}", opcode), - Error::InvalidStackOperation => "Invalid stack operation".fmt(f), - Error::InvalidAltstackOperation => "Invalid altstack operation".fmt(f), - Error::UnbalancedConditional => "Unbalanced conditional".fmt(f), - Error::InvalidSplitRange => "Invalid OP_SPLIT range".fmt(f), - Error::InvalidBitwiseOperation => "Invalid bitwise operation (check length of inputs)".fmt(f), - Error::DivisionByZero => "Invalid division operation".fmt(f), - Error::ImpossibleEncoding => "The requested encoding is impossible to satisfy".fmt(f), - - // CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY - Error::NegativeLocktime => "Negative locktime".fmt(f), - Error::UnsatisfiedLocktime => "UnsatisfiedLocktime".fmt(f), - - // BIP62 - Error::SignatureHashtype => "Invalid Signature Hashtype".fmt(f), - Error::SignatureDer => "Invalid Signature".fmt(f), - Error::SignatureIllegalForkId => "Illegal use of SIGHASH_FORKID".fmt(f), - Error::SignatureMustUseForkId => "Signature must use SIGHASH_FORKID".fmt(f), - Error::Minimaldata => "Check minimaldata failed".fmt(f), - Error::SignaturePushOnly => "Only push opcodes are allowed in this signature".fmt(f), - Error::SignatureHighS => "Invalid High S in Signature".fmt(f), - Error::SignatureNullDummy => "Multisig extra stack element is not empty".fmt(f), - Error::PubkeyType => "Invalid Pubkey".fmt(f), - Error::Cleanstack => "Only one element is expected to remain at stack at the end of execution".fmt(f), - - // Softfork safeness - Error::DiscourageUpgradableNops => "Discourage Upgradable Nops".fmt(f), - Error::DiscourageUpgradableWitnessProgram => "Discourage Upgradable Witness Program".fmt(f), - - // SegWit-related errors - Error::WitnessProgramWrongLength => "Witness program has incorrect length".fmt(f), - Error::WitnessProgramWitnessEmpty => "Witness program was passed an empty witness".fmt(f), - Error::WitnessProgramMismatch => "Witness program hash mismatch".fmt(f), - Error::WitnessMalleated => "Witness requires empty scriptSig".fmt(f), - Error::WitnessMalleatedP2SH => "Witness requires only-redeemscript scriptSig".fmt(f), - Error::WitnessUnexpected => "Witness provided for non-witness script".fmt(f), - Error::WitnessPubKeyType => "Using non-compressed keys in segwit".fmt(f), - } - } -} diff --git a/cxrml/bridge/btc/src/script/flags.rs b/cxrml/bridge/btc/src/script/flags.rs deleted file mode 100644 index c392fad0c5be4..0000000000000 --- a/cxrml/bridge/btc/src/script/flags.rs +++ /dev/null @@ -1,188 +0,0 @@ -//! Script interpreter verification flags - -/// Script interpreter verification flags -#[derive(Default, Debug, PartialEq)] -pub struct VerificationFlags { - pub none: bool, - - /// Evaluate P2SH subscripts (softfork safe, BIP16). - pub verify_p2sh: bool, - - /// Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure. - /// Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure. - /// (softfork safe, but not used or intended as a consensus rule). - pub verify_strictenc: bool, - - /// Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, BIP62 rule 1) - pub verify_dersig: bool, - - /// Passing a non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure - /// (softfork safe, BIP62 rule 5). - pub verify_low_s: bool, - - /// verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7). - pub verify_nulldummy: bool, - - /// Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2). - pub verify_sigpushonly: bool, - - /// Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct - /// pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating - /// any other push causes the script to fail (BIP62 rule 3). - /// In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4). - /// (softfork safe) - pub verify_minimaldata: bool, - - /// Discourage use of NOPs reserved for upgrades (NOP1-10) - /// - /// Provided so that nodes can avoid accepting or mining transactions - /// containing executed NOP's whose meaning may change after a soft-fork, - /// thus rendering the script invalid; with this flag set executing - /// discouraged NOPs fails the script. This verification flag will never be - /// a mandatory flag applied to scripts in a block. NOPs that are not - /// executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected. - pub verify_discourage_upgradable_nops: bool, - - /// Require that only a single stack element remains after evaluation. This changes the success criterion from - /// "At least one stack element must remain, and when interpreted as a boolean, it must be true" to - /// "Exactly one stack element must remain, and when interpreted as a boolean, it must be true". - /// (softfork safe, BIP62 rule 6) - /// Note: CLEANSTACK should never be used without P2SH or WITNESS. - pub verify_cleanstack: bool, - - /// Verify CHECKLOCKTIMEVERIFY - /// - /// See BIP65 for details. - pub verify_locktime: bool, - - /// support CHECKSEQUENCEVERIFY opcode - /// - /// See BIP112 for details - pub verify_checksequence: bool, - - /// Support segregated witness - pub verify_witness: bool, - - /// Making v1-v16 witness program non-standard - pub verify_discourage_upgradable_witness_program: bool, - - /// Support OP_CAT opcode - pub verify_concat: bool, - - /// Support OP_SPLIT opcode - /// - /// This opcode replaces OP_SUBSTR => enabling both OP_SPLIT && OP_SUBSTR would be an error - pub verify_split: bool, - - /// Support OP_AND opcode - pub verify_and: bool, - - /// Support OP_OR opcode - pub verify_or: bool, - - /// Support OP_XOR opcode - pub verify_xor: bool, - - /// Support OP_DIV opcode - pub verify_div: bool, - - /// Support OP_MOD opcode - pub verify_mod: bool, - - /// Support OP_BIN2NUM opcode - /// - /// This opcode replaces OP_RIGHT => enabling both OP_BIN2NUM && OP_RIGHT would be an error - pub verify_bin2num: bool, - - /// Support OP_NUM2BIN opcode - /// - /// This opcode replaces OP_LEFT => enabling both OP_NUM2BIN && OP_LEFT would be an error - pub verify_num2bin: bool, -} - -impl VerificationFlags { - pub fn verify_p2sh(mut self, value: bool) -> Self { - self.verify_p2sh = value; - self - } - - pub fn verify_strictenc(mut self, value: bool) -> Self { - self.verify_strictenc = value; - self - } - - pub fn verify_locktime(mut self, value: bool) -> Self { - self.verify_locktime = value; - self - } - - pub fn verify_checksequence(mut self, value: bool) -> Self { - self.verify_checksequence = value; - self - } - - pub fn verify_dersig(mut self, value: bool) -> Self { - self.verify_dersig = value; - self - } - - pub fn verify_witness(mut self, value: bool) -> Self { - self.verify_witness = value; - self - } - - pub fn verify_nulldummy(mut self, value: bool) -> Self { - self.verify_nulldummy = value; - self - } - - pub fn verify_discourage_upgradable_witness_program(mut self, value: bool) -> Self { - self.verify_discourage_upgradable_witness_program = value; - self - } - - pub fn verify_concat(mut self, value: bool) -> Self { - self.verify_concat = value; - self - } - - pub fn verify_split(mut self, value: bool) -> Self { - self.verify_split = value; - self - } - - pub fn verify_and(mut self, value: bool) -> Self { - self.verify_and = value; - self - } - - pub fn verify_or(mut self, value: bool) -> Self { - self.verify_or = value; - self - } - - pub fn verify_xor(mut self, value: bool) -> Self { - self.verify_xor = value; - self - } - - pub fn verify_div(mut self, value: bool) -> Self { - self.verify_div = value; - self - } - - pub fn verify_mod(mut self, value: bool) -> Self { - self.verify_mod = value; - self - } - - pub fn verify_bin2num(mut self, value: bool) -> Self { - self.verify_bin2num = value; - self - } - - pub fn verify_num2bin(mut self, value: bool) -> Self { - self.verify_num2bin = value; - self - } -} diff --git a/cxrml/bridge/btc/src/script/mod.rs b/cxrml/bridge/btc/src/script/mod.rs deleted file mode 100644 index 0fdc42024bac2..0000000000000 --- a/cxrml/bridge/btc/src/script/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2018 Chainpool - -mod flags; -mod error; -mod opcode; -mod num; -mod stack; -pub mod script; - -use bitcrypto as crypto; -use chain; -use keys; -use primitives::{bytes, hash}; -pub use self::opcode::Opcode; -pub use self::error::Error; diff --git a/cxrml/bridge/btc/src/script/num.rs b/cxrml/bridge/btc/src/script/num.rs deleted file mode 100644 index 4ae4c99aa0167..0000000000000 --- a/cxrml/bridge/btc/src/script/num.rs +++ /dev/null @@ -1,267 +0,0 @@ -//! Script numeric - -use rstd::ops; -use super::bytes::Bytes; -use super::error::Error; - -/// Script numeric -/// -/// Numeric opcodes (`OP_1ADD`, etc) are restricted to operating on 4-byte integers. -/// The semantics are subtle, though: operands must be in the range [-2^31 +1...2^31 -1], -/// but results may overflow (and are valid as long as they are not used in a subsequent -/// numeric operation). `CScriptNum` enforces those semantics by storing results as -/// an int64 and allowing out-of-range values to be returned as a vector of bytes but -/// throwing an exception if arithmetic is done or the result is interpreted as an integer. -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] -pub struct Num { - value: i64, -} - -impl From for Num { - fn from(i: bool) -> Self { - let v = if i { 1 } else { 0 }; - Num { - value: v - } - } -} - -impl From for Num { - fn from(i: u8) -> Self { - Num { - value: i as i64 - } - } -} - -impl From for Num { - fn from(i: u32) -> Self { - Num { - value: i as i64 - } - } -} - -impl From for Num { - fn from(i: usize) -> Self { - Num { - value: i as i64 - } - } -} - -impl From for Num { - fn from(i: i32) -> Self { - Num { - value: i as i64 - } - } -} - -impl From for Num { - fn from(i: i64) -> Self { - Num { - value: i - } - } -} - -impl From for i64 { - fn from(n: Num) -> Self { - n.value - } -} - -impl From for u32 { - fn from(n: Num) -> Self { - n.value as u32 - } -} - -impl From for usize { - fn from(n: Num) -> Self { - n.value as usize - } -} - -impl Num { - /// Reduce the data size to its minimal, and then try to convert it to a num. - pub fn minimally_encode(data: &[u8], max_size: usize) -> Result { - match data.last() { - None => Num::from_slice(data, true, max_size), - Some(last) => { - if *last != 0x00 && *last != 0x80 { - return Num::from_slice(data, true, max_size); - } - - if data.len() == 1 { - return Num::from_slice(&[], true, max_size); - } - - if data[data.len() - 2] & 0x80 == 0x80 { - return Num::from_slice(data, true, max_size); - } - - // We are not minimally encoded. Create a vector so that we can trim the result. The last byte is not included, - // as we first trim all zeros. And then a conditional to decide what to do with the last byte. - let mut data: Vec = data[0..(data.len()-1)].iter().cloned().rev().skip_while(|x| *x == 0x00).collect(); - data.reverse(); - - if data.len() == 0 { - // At this point, last is either equal to 0x00 or 0x80. The result is empty. - return Num::from_slice(&[], true, max_size); - } - - let second_last = *data.last().expect("vec emptiness is checked above; qed"); - if second_last & 0x80 == 0x80 { - data.push(*last); - } else { - *data.last_mut().expect("vec emptiness is checked above; qed") |= *last - } - - Num::from_slice(&data, true, max_size) - } - } - } - - pub fn from_slice(data: &[u8], require_minimal: bool, max_size: usize) -> Result { - if data.len() > max_size { - return Err(Error::NumberOverflow); - } - - if data.is_empty() { - return Ok(0u8.into()); - } - - // Check that the number is encoded with the minimum possible - // number of bytes. - // - // If the most-significant-byte - excluding the sign bit - is zero - // then we're not minimal. Note how this test also rejects the - // negative-zero encoding, 0x80. - if require_minimal && - (data.last().unwrap() & 0x7f) == 0 && - (data.len() <= 1 || (data[data.len() - 2] & 0x80) == 0) { - return Err(Error::NumberNotMinimallyEncoded) - } - - let mut result = 0i64; - for (i, item) in data.iter().enumerate() { - result |= (*item as i64) << (8 * i); - } - - // If the input vector's most significant byte is 0x80, remove it from - // the result's msb and return a negative. - if data.last().unwrap() & 0x80 != 0 { - Ok((-(result & !(0x80i64 << (8 * (data.len() - 1))))).into()) - } else { - Ok(result.into()) - } - } - - pub fn to_bytes(&self) -> Bytes { - if self.value == 0 { - return Bytes::default(); - } - - let mut result = vec![]; - let negative = self.value < 0; - let mut absvalue = if negative { - (-self.value) as u64 - } else { - self.value as u64 - }; - - while absvalue > 0 { - result.push(absvalue as u8 & 0xff); - absvalue >>= 8; - } - - // - If the most significant byte is >= 0x80 and the value is positive, push a - // new zero-byte to make the significant byte < 0x80 again. - - // - If the most significant byte is >= 0x80 and the value is negative, push a - // new 0x80 byte that will be popped off when converting to an integral. - - // - If the most significant byte is < 0x80 and the value is negative, add - // 0x80 to it, since it will be subtracted and interpreted as a negative when - // converting to an integral. - - if result[result.len() - 1] & 0x80 != 0 { - if negative { - result.push(0x80); - } else { - result.push(0); - } - } else if negative { - let rlen = result.len(); - result[rlen - 1] |= 0x80; - } - - result.into() - } - - pub fn is_negative(&self) -> bool { - self.value < 0 - } - - pub fn is_zero(&self) -> bool { - self.value == 0 - } - - pub fn abs(&self) -> Num { - if self.value < 0 { - (-self.value).into() - } else { - self.value.into() - } - } -} - -impl ops::BitAnd for Num { - type Output = Self; - - fn bitand(self, rhs: Self) -> Self::Output { - (self.value & rhs.value).into() - } -} - -impl ops::Add for Num { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - (self.value + rhs.value).into() - } -} - -impl ops::Sub for Num { - type Output = Self; - - fn sub(self, rhs: Self) -> Self::Output { - (self.value - rhs.value).into() - } -} - -impl ops::Neg for Num { - type Output = Self; - - fn neg(self) -> Self::Output { - (-self.value).into() - } -} - -impl ops::Div for Num { - type Output = Self; - - fn div(self, rhs: Self) -> Self::Output { - (self.value / rhs.value).into() - } -} - -impl ops::Rem for Num { - type Output = Self; - - fn rem(self, rhs: Self) -> Self::Output { - (self.value % rhs.value).into() - } -} diff --git a/cxrml/bridge/btc/src/script/opcode.rs b/cxrml/bridge/btc/src/script/opcode.rs deleted file mode 100644 index a4f021b96dd24..0000000000000 --- a/cxrml/bridge/btc/src/script/opcode.rs +++ /dev/null @@ -1,695 +0,0 @@ -//! Script opcodes. - -#[cfg(feature = "std")] -use std::fmt; -use super::flags::VerificationFlags; - -/// Script opcodes. -#[repr(u8)] -#[allow(non_camel_case_types)] -#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)] -pub enum Opcode { - // push value - OP_0 = 0x00, - OP_PUSHBYTES_1 = 0x01, - OP_PUSHBYTES_2 = 0x02, - OP_PUSHBYTES_3 = 0x03, - OP_PUSHBYTES_4 = 0x04, - OP_PUSHBYTES_5 = 0x05, - OP_PUSHBYTES_6 = 0x06, - OP_PUSHBYTES_7 = 0x07, - OP_PUSHBYTES_8 = 0x08, - OP_PUSHBYTES_9 = 0x09, - OP_PUSHBYTES_10 = 0x0a, - OP_PUSHBYTES_11 = 0x0b, - OP_PUSHBYTES_12 = 0x0c, - OP_PUSHBYTES_13 = 0x0d, - OP_PUSHBYTES_14 = 0x0e, - OP_PUSHBYTES_15 = 0x0f, - OP_PUSHBYTES_16 = 0x10, - OP_PUSHBYTES_17 = 0x11, - OP_PUSHBYTES_18 = 0x12, - OP_PUSHBYTES_19 = 0x13, - OP_PUSHBYTES_20 = 0x14, - OP_PUSHBYTES_21 = 0x15, - OP_PUSHBYTES_22 = 0x16, - OP_PUSHBYTES_23 = 0x17, - OP_PUSHBYTES_24 = 0x18, - OP_PUSHBYTES_25 = 0x19, - OP_PUSHBYTES_26 = 0x1a, - OP_PUSHBYTES_27 = 0x1b, - OP_PUSHBYTES_28 = 0x1c, - OP_PUSHBYTES_29 = 0x1d, - OP_PUSHBYTES_30 = 0x1e, - OP_PUSHBYTES_31 = 0x1f, - OP_PUSHBYTES_32 = 0x20, - OP_PUSHBYTES_33 = 0x21, - OP_PUSHBYTES_34 = 0x22, - OP_PUSHBYTES_35 = 0x23, - OP_PUSHBYTES_36 = 0x24, - OP_PUSHBYTES_37 = 0x25, - OP_PUSHBYTES_38 = 0x26, - OP_PUSHBYTES_39 = 0x27, - OP_PUSHBYTES_40 = 0x28, - OP_PUSHBYTES_41 = 0x29, - OP_PUSHBYTES_42 = 0x2a, - OP_PUSHBYTES_43 = 0x2b, - OP_PUSHBYTES_44 = 0x2c, - OP_PUSHBYTES_45 = 0x2d, - OP_PUSHBYTES_46 = 0x2e, - OP_PUSHBYTES_47 = 0x2f, - OP_PUSHBYTES_48 = 0x30, - OP_PUSHBYTES_49 = 0x31, - OP_PUSHBYTES_50 = 0x32, - OP_PUSHBYTES_51 = 0x33, - OP_PUSHBYTES_52 = 0x34, - OP_PUSHBYTES_53 = 0x35, - OP_PUSHBYTES_54 = 0x36, - OP_PUSHBYTES_55 = 0x37, - OP_PUSHBYTES_56 = 0x38, - OP_PUSHBYTES_57 = 0x39, - OP_PUSHBYTES_58 = 0x3a, - OP_PUSHBYTES_59 = 0x3b, - OP_PUSHBYTES_60 = 0x3c, - OP_PUSHBYTES_61 = 0x3d, - OP_PUSHBYTES_62 = 0x3e, - OP_PUSHBYTES_63 = 0x3f, - OP_PUSHBYTES_64 = 0x40, - OP_PUSHBYTES_65 = 0x41, - OP_PUSHBYTES_66 = 0x42, - OP_PUSHBYTES_67 = 0x43, - OP_PUSHBYTES_68 = 0x44, - OP_PUSHBYTES_69 = 0x45, - OP_PUSHBYTES_70 = 0x46, - OP_PUSHBYTES_71 = 0x47, - OP_PUSHBYTES_72 = 0x48, - OP_PUSHBYTES_73 = 0x49, - OP_PUSHBYTES_74 = 0x4a, - OP_PUSHBYTES_75 = 0x4b, - OP_PUSHDATA1 = 0x4c, - OP_PUSHDATA2 = 0x4d, - OP_PUSHDATA4 = 0x4e, - OP_1NEGATE = 0x4f, - OP_RESERVED = 0x50, - OP_1 = 0x51, - OP_2 = 0x52, - OP_3 = 0x53, - OP_4 = 0x54, - OP_5 = 0x55, - OP_6 = 0x56, - OP_7 = 0x57, - OP_8 = 0x58, - OP_9 = 0x59, - OP_10 = 0x5a, - OP_11 = 0x5b, - OP_12 = 0x5c, - OP_13 = 0x5d, - OP_14 = 0x5e, - OP_15 = 0x5f, - OP_16 = 0x60, - - // control - OP_NOP = 0x61, - OP_VER = 0x62, - OP_IF = 0x63, - OP_NOTIF = 0x64, - OP_VERIF = 0x65, - OP_VERNOTIF = 0x66, - OP_ELSE = 0x67, - OP_ENDIF = 0x68, - OP_VERIFY = 0x69, - OP_RETURN = 0x6a, - - // stack ops - OP_TOALTSTACK = 0x6b, - OP_FROMALTSTACK = 0x6c, - OP_2DROP = 0x6d, - OP_2DUP = 0x6e, - OP_3DUP = 0x6f, - OP_2OVER = 0x70, - OP_2ROT = 0x71, - OP_2SWAP = 0x72, - OP_IFDUP = 0x73, - OP_DEPTH = 0x74, - OP_DROP = 0x75, - OP_DUP = 0x76, - OP_NIP = 0x77, - OP_OVER = 0x78, - OP_PICK = 0x79, - OP_ROLL = 0x7a, - OP_ROT = 0x7b, - OP_SWAP = 0x7c, - OP_TUCK = 0x7d, - - // splice ops - OP_CAT = 0x7e, - OP_SUBSTR = 0x7f, - OP_LEFT = 0x80, - OP_RIGHT = 0x81, - OP_SIZE = 0x82, - - // bit logic - OP_INVERT = 0x83, - OP_AND = 0x84, - OP_OR = 0x85, - OP_XOR = 0x86, - OP_EQUAL = 0x87, - OP_EQUALVERIFY = 0x88, - OP_RESERVED1 = 0x89, - OP_RESERVED2 = 0x8a, - - // numeric - OP_1ADD = 0x8b, - OP_1SUB = 0x8c, - OP_2MUL = 0x8d, - OP_2DIV = 0x8e, - OP_NEGATE = 0x8f, - OP_ABS = 0x90, - OP_NOT = 0x91, - OP_0NOTEQUAL = 0x92, - - OP_ADD = 0x93, - OP_SUB = 0x94, - OP_MUL = 0x95, - OP_DIV = 0x96, - OP_MOD = 0x97, - OP_LSHIFT = 0x98, - OP_RSHIFT = 0x99, - - OP_BOOLAND = 0x9a, - OP_BOOLOR = 0x9b, - OP_NUMEQUAL = 0x9c, - OP_NUMEQUALVERIFY = 0x9d, - OP_NUMNOTEQUAL = 0x9e, - OP_LESSTHAN = 0x9f, - OP_GREATERTHAN = 0xa0, - OP_LESSTHANOREQUAL = 0xa1, - OP_GREATERTHANOREQUAL = 0xa2, - OP_MIN = 0xa3, - OP_MAX = 0xa4, - - OP_WITHIN = 0xa5, - - // crypto - OP_RIPEMD160 = 0xa6, - OP_SHA1 = 0xa7, - OP_SHA256 = 0xa8, - OP_HASH160 = 0xa9, - OP_HASH256 = 0xaa, - OP_CODESEPARATOR = 0xab, - OP_CHECKSIG = 0xac, - OP_CHECKSIGVERIFY = 0xad, - OP_CHECKMULTISIG = 0xae, - OP_CHECKMULTISIGVERIFY = 0xaf, - - // expansion - OP_NOP1 = 0xb0, - OP_CHECKLOCKTIMEVERIFY = 0xb1, - //OP_NOP2 = OP_CHECKLOCKTIMEVERIFY, - OP_CHECKSEQUENCEVERIFY = 0xb2, - //OP_NOP3 = OP_CHECKSEQUENCEVERIFY, - OP_NOP4 = 0xb3, - OP_NOP5 = 0xb4, - OP_NOP6 = 0xb5, - OP_NOP7 = 0xb6, - OP_NOP8 = 0xb7, - OP_NOP9 = 0xb8, - OP_NOP10 = 0xb9, -} - -#[cfg(feature = "std")] -impl fmt::Display for Opcode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(self, f) - } -} - -impl Opcode { - pub fn from_u8(u: u8) -> Option { - use self::Opcode::*; - match u { - 0x00 => Some(OP_0), - 0x01 => Some(OP_PUSHBYTES_1), - 0x02 => Some(OP_PUSHBYTES_2), - 0x03 => Some(OP_PUSHBYTES_3), - 0x04 => Some(OP_PUSHBYTES_4), - 0x05 => Some(OP_PUSHBYTES_5), - 0x06 => Some(OP_PUSHBYTES_6), - 0x07 => Some(OP_PUSHBYTES_7), - 0x08 => Some(OP_PUSHBYTES_8), - 0x09 => Some(OP_PUSHBYTES_9), - 0x0a => Some(OP_PUSHBYTES_10), - 0x0b => Some(OP_PUSHBYTES_11), - 0x0c => Some(OP_PUSHBYTES_12), - 0x0d => Some(OP_PUSHBYTES_13), - 0x0e => Some(OP_PUSHBYTES_14), - 0x0f => Some(OP_PUSHBYTES_15), - 0x10 => Some(OP_PUSHBYTES_16), - 0x11 => Some(OP_PUSHBYTES_17), - 0x12 => Some(OP_PUSHBYTES_18), - 0x13 => Some(OP_PUSHBYTES_19), - 0x14 => Some(OP_PUSHBYTES_20), - 0x15 => Some(OP_PUSHBYTES_21), - 0x16 => Some(OP_PUSHBYTES_22), - 0x17 => Some(OP_PUSHBYTES_23), - 0x18 => Some(OP_PUSHBYTES_24), - 0x19 => Some(OP_PUSHBYTES_25), - 0x1a => Some(OP_PUSHBYTES_26), - 0x1b => Some(OP_PUSHBYTES_27), - 0x1c => Some(OP_PUSHBYTES_28), - 0x1d => Some(OP_PUSHBYTES_29), - 0x1e => Some(OP_PUSHBYTES_30), - 0x1f => Some(OP_PUSHBYTES_31), - 0x20 => Some(OP_PUSHBYTES_32), - 0x21 => Some(OP_PUSHBYTES_33), - 0x22 => Some(OP_PUSHBYTES_34), - 0x23 => Some(OP_PUSHBYTES_35), - 0x24 => Some(OP_PUSHBYTES_36), - 0x25 => Some(OP_PUSHBYTES_37), - 0x26 => Some(OP_PUSHBYTES_38), - 0x27 => Some(OP_PUSHBYTES_39), - 0x28 => Some(OP_PUSHBYTES_40), - 0x29 => Some(OP_PUSHBYTES_41), - 0x2a => Some(OP_PUSHBYTES_42), - 0x2b => Some(OP_PUSHBYTES_43), - 0x2c => Some(OP_PUSHBYTES_44), - 0x2d => Some(OP_PUSHBYTES_45), - 0x2e => Some(OP_PUSHBYTES_46), - 0x2f => Some(OP_PUSHBYTES_47), - 0x30 => Some(OP_PUSHBYTES_48), - 0x31 => Some(OP_PUSHBYTES_49), - 0x32 => Some(OP_PUSHBYTES_50), - 0x33 => Some(OP_PUSHBYTES_51), - 0x34 => Some(OP_PUSHBYTES_52), - 0x35 => Some(OP_PUSHBYTES_53), - 0x36 => Some(OP_PUSHBYTES_54), - 0x37 => Some(OP_PUSHBYTES_55), - 0x38 => Some(OP_PUSHBYTES_56), - 0x39 => Some(OP_PUSHBYTES_57), - 0x3a => Some(OP_PUSHBYTES_58), - 0x3b => Some(OP_PUSHBYTES_59), - 0x3c => Some(OP_PUSHBYTES_60), - 0x3d => Some(OP_PUSHBYTES_61), - 0x3e => Some(OP_PUSHBYTES_62), - 0x3f => Some(OP_PUSHBYTES_63), - 0x40 => Some(OP_PUSHBYTES_64), - 0x41 => Some(OP_PUSHBYTES_65), - 0x42 => Some(OP_PUSHBYTES_66), - 0x43 => Some(OP_PUSHBYTES_67), - 0x44 => Some(OP_PUSHBYTES_68), - 0x45 => Some(OP_PUSHBYTES_69), - 0x46 => Some(OP_PUSHBYTES_70), - 0x47 => Some(OP_PUSHBYTES_71), - 0x48 => Some(OP_PUSHBYTES_72), - 0x49 => Some(OP_PUSHBYTES_73), - 0x4a => Some(OP_PUSHBYTES_74), - 0x4b => Some(OP_PUSHBYTES_75), - 0x4c => Some(OP_PUSHDATA1), - 0x4d => Some(OP_PUSHDATA2), - 0x4e => Some(OP_PUSHDATA4), - 0x4f => Some(OP_1NEGATE), - 0x50 => Some(OP_RESERVED), - 0x51 => Some(OP_1), - 0x52 => Some(OP_2), - 0x53 => Some(OP_3), - 0x54 => Some(OP_4), - 0x55 => Some(OP_5), - 0x56 => Some(OP_6), - 0x57 => Some(OP_7), - 0x58 => Some(OP_8), - 0x59 => Some(OP_9), - 0x5a => Some(OP_10), - 0x5b => Some(OP_11), - 0x5c => Some(OP_12), - 0x5d => Some(OP_13), - 0x5e => Some(OP_14), - 0x5f => Some(OP_15), - 0x60 => Some(OP_16), - - // control - 0x61 => Some(OP_NOP), - 0x62 => Some(OP_VER), - 0x63 => Some(OP_IF), - 0x64 => Some(OP_NOTIF), - 0x65 => Some(OP_VERIF), - 0x66 => Some(OP_VERNOTIF), - 0x67 => Some(OP_ELSE), - 0x68 => Some(OP_ENDIF), - 0x69 => Some(OP_VERIFY), - 0x6a => Some(OP_RETURN), - - // stack ops - 0x6b => Some(OP_TOALTSTACK), - 0x6c => Some(OP_FROMALTSTACK), - 0x6d => Some(OP_2DROP), - 0x6e => Some(OP_2DUP), - 0x6f => Some(OP_3DUP), - 0x70 => Some(OP_2OVER), - 0x71 => Some(OP_2ROT), - 0x72 => Some(OP_2SWAP), - 0x73 => Some(OP_IFDUP), - 0x74 => Some(OP_DEPTH), - 0x75 => Some(OP_DROP), - 0x76 => Some(OP_DUP), - 0x77 => Some(OP_NIP), - 0x78 => Some(OP_OVER), - 0x79 => Some(OP_PICK), - 0x7a => Some(OP_ROLL), - 0x7b => Some(OP_ROT), - 0x7c => Some(OP_SWAP), - 0x7d => Some(OP_TUCK), - - // splice ops - 0x7e => Some(OP_CAT), - 0x7f => Some(OP_SUBSTR), - 0x80 => Some(OP_LEFT), - 0x81 => Some(OP_RIGHT), - 0x82 => Some(OP_SIZE), - - // bit logic - 0x83 => Some(OP_INVERT), - 0x84 => Some(OP_AND), - 0x85 => Some(OP_OR), - 0x86 => Some(OP_XOR), - 0x87 => Some(OP_EQUAL), - 0x88 => Some(OP_EQUALVERIFY), - 0x89 => Some(OP_RESERVED1), - 0x8a => Some(OP_RESERVED2), - - // numeric - 0x8b => Some(OP_1ADD), - 0x8c => Some(OP_1SUB), - 0x8d => Some(OP_2MUL), - 0x8e => Some(OP_2DIV), - 0x8f => Some(OP_NEGATE), - 0x90 => Some(OP_ABS), - 0x91 => Some(OP_NOT), - 0x92 => Some(OP_0NOTEQUAL), - - 0x93 => Some(OP_ADD), - 0x94 => Some(OP_SUB), - 0x95 => Some(OP_MUL), - 0x96 => Some(OP_DIV), - 0x97 => Some(OP_MOD), - 0x98 => Some(OP_LSHIFT), - 0x99 => Some(OP_RSHIFT), - - 0x9a => Some(OP_BOOLAND), - 0x9b => Some(OP_BOOLOR), - 0x9c => Some(OP_NUMEQUAL), - 0x9d => Some(OP_NUMEQUALVERIFY), - 0x9e => Some(OP_NUMNOTEQUAL), - 0x9f => Some(OP_LESSTHAN), - 0xa0 => Some(OP_GREATERTHAN), - 0xa1 => Some(OP_LESSTHANOREQUAL), - 0xa2 => Some(OP_GREATERTHANOREQUAL), - 0xa3 => Some(OP_MIN), - 0xa4 => Some(OP_MAX), - - 0xa5 => Some(OP_WITHIN), - - // crypto - 0xa6 => Some(OP_RIPEMD160), - 0xa7 => Some(OP_SHA1), - 0xa8 => Some(OP_SHA256), - 0xa9 => Some(OP_HASH160), - 0xaa => Some(OP_HASH256), - 0xab => Some(OP_CODESEPARATOR), - 0xac => Some(OP_CHECKSIG), - 0xad => Some(OP_CHECKSIGVERIFY), - 0xae => Some(OP_CHECKMULTISIG), - 0xaf => Some(OP_CHECKMULTISIGVERIFY), - - // expansion - 0xb0 => Some(OP_NOP1), - 0xb1 => Some(OP_CHECKLOCKTIMEVERIFY), - //OP_NOP2 = OP_CHECKLOCKTIMEVERIFY, - 0xb2 => Some(OP_CHECKSEQUENCEVERIFY), - //OP_NOP3 = OP_CHECKSEQUENCEVERIFY, - 0xb3 => Some(OP_NOP4), - 0xb4 => Some(OP_NOP5), - 0xb5 => Some(OP_NOP6), - 0xb6 => Some(OP_NOP7), - 0xb7 => Some(OP_NOP8), - 0xb8 => Some(OP_NOP9), - 0xb9 => Some(OP_NOP10), - _ => None, - } - } - - pub fn is_disabled(&self, flags: &VerificationFlags) -> bool { - use self::Opcode::*; - match *self { - OP_CAT if !flags.verify_concat => true, - OP_SUBSTR if !flags.verify_split => true, - OP_AND if !flags.verify_and => true, - OP_OR if !flags.verify_or => true, - OP_XOR if !flags.verify_xor => true, - OP_DIV if !flags.verify_div => true, - OP_MOD if !flags.verify_mod => true, - OP_RIGHT if !flags.verify_bin2num => true, - OP_LEFT if !flags.verify_num2bin => true, - OP_INVERT | OP_2MUL | OP_2DIV | - OP_MUL | OP_LSHIFT | OP_RSHIFT => true, - _ => false, - } - } - - /// Returns true if opcode is countable - pub fn is_countable(&self) -> bool { - *self > Opcode::OP_16 - } - - pub fn is_simple_push(&self) -> bool { - *self < Opcode::OP_PUSHDATA1 - } - - pub fn is_push_value(&self) -> bool { - *self >= Opcode::OP_1NEGATE && *self <= Opcode::OP_16 - } - - pub fn is_within_op_n(&self) -> bool { - *self >= Opcode::OP_1 && *self <= Opcode::OP_16 - } - - pub fn decode_op_n(&self) -> u8 { - assert!(self.is_within_op_n()); - let value = *self as u8; - let op0 = Opcode::OP_1 as u8 - 1; - value - op0 - } -} - -#[cfg(test)] -mod tests { - use super::Opcode; - - #[test] - fn test_to_from_opcode() { - - // push value - assert_eq!(Opcode::OP_0, Opcode::from_u8(Opcode::OP_0 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_1, Opcode::from_u8(Opcode::OP_PUSHBYTES_1 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_2, Opcode::from_u8(Opcode::OP_PUSHBYTES_2 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_3, Opcode::from_u8(Opcode::OP_PUSHBYTES_3 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_4, Opcode::from_u8(Opcode::OP_PUSHBYTES_4 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_5, Opcode::from_u8(Opcode::OP_PUSHBYTES_5 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_6, Opcode::from_u8(Opcode::OP_PUSHBYTES_6 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_7, Opcode::from_u8(Opcode::OP_PUSHBYTES_7 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_8, Opcode::from_u8(Opcode::OP_PUSHBYTES_8 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_9, Opcode::from_u8(Opcode::OP_PUSHBYTES_9 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_10, Opcode::from_u8(Opcode::OP_PUSHBYTES_10 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_11, Opcode::from_u8(Opcode::OP_PUSHBYTES_11 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_12, Opcode::from_u8(Opcode::OP_PUSHBYTES_12 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_13, Opcode::from_u8(Opcode::OP_PUSHBYTES_13 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_14, Opcode::from_u8(Opcode::OP_PUSHBYTES_14 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_15, Opcode::from_u8(Opcode::OP_PUSHBYTES_15 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_16, Opcode::from_u8(Opcode::OP_PUSHBYTES_16 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_17, Opcode::from_u8(Opcode::OP_PUSHBYTES_17 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_18, Opcode::from_u8(Opcode::OP_PUSHBYTES_18 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_19, Opcode::from_u8(Opcode::OP_PUSHBYTES_19 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_20, Opcode::from_u8(Opcode::OP_PUSHBYTES_20 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_21, Opcode::from_u8(Opcode::OP_PUSHBYTES_21 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_22, Opcode::from_u8(Opcode::OP_PUSHBYTES_22 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_23, Opcode::from_u8(Opcode::OP_PUSHBYTES_23 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_24, Opcode::from_u8(Opcode::OP_PUSHBYTES_24 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_25, Opcode::from_u8(Opcode::OP_PUSHBYTES_25 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_26, Opcode::from_u8(Opcode::OP_PUSHBYTES_26 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_27, Opcode::from_u8(Opcode::OP_PUSHBYTES_27 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_28, Opcode::from_u8(Opcode::OP_PUSHBYTES_28 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_29, Opcode::from_u8(Opcode::OP_PUSHBYTES_29 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_30, Opcode::from_u8(Opcode::OP_PUSHBYTES_30 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_31, Opcode::from_u8(Opcode::OP_PUSHBYTES_31 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_32, Opcode::from_u8(Opcode::OP_PUSHBYTES_32 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_33, Opcode::from_u8(Opcode::OP_PUSHBYTES_33 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_34, Opcode::from_u8(Opcode::OP_PUSHBYTES_34 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_35, Opcode::from_u8(Opcode::OP_PUSHBYTES_35 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_36, Opcode::from_u8(Opcode::OP_PUSHBYTES_36 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_37, Opcode::from_u8(Opcode::OP_PUSHBYTES_37 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_38, Opcode::from_u8(Opcode::OP_PUSHBYTES_38 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_39, Opcode::from_u8(Opcode::OP_PUSHBYTES_39 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_40, Opcode::from_u8(Opcode::OP_PUSHBYTES_40 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_41, Opcode::from_u8(Opcode::OP_PUSHBYTES_41 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_42, Opcode::from_u8(Opcode::OP_PUSHBYTES_42 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_43, Opcode::from_u8(Opcode::OP_PUSHBYTES_43 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_44, Opcode::from_u8(Opcode::OP_PUSHBYTES_44 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_45, Opcode::from_u8(Opcode::OP_PUSHBYTES_45 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_46, Opcode::from_u8(Opcode::OP_PUSHBYTES_46 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_47, Opcode::from_u8(Opcode::OP_PUSHBYTES_47 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_48, Opcode::from_u8(Opcode::OP_PUSHBYTES_48 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_49, Opcode::from_u8(Opcode::OP_PUSHBYTES_49 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_50, Opcode::from_u8(Opcode::OP_PUSHBYTES_50 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_51, Opcode::from_u8(Opcode::OP_PUSHBYTES_51 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_52, Opcode::from_u8(Opcode::OP_PUSHBYTES_52 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_53, Opcode::from_u8(Opcode::OP_PUSHBYTES_53 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_54, Opcode::from_u8(Opcode::OP_PUSHBYTES_54 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_55, Opcode::from_u8(Opcode::OP_PUSHBYTES_55 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_56, Opcode::from_u8(Opcode::OP_PUSHBYTES_56 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_57, Opcode::from_u8(Opcode::OP_PUSHBYTES_57 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_58, Opcode::from_u8(Opcode::OP_PUSHBYTES_58 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_59, Opcode::from_u8(Opcode::OP_PUSHBYTES_59 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_60, Opcode::from_u8(Opcode::OP_PUSHBYTES_60 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_61, Opcode::from_u8(Opcode::OP_PUSHBYTES_61 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_62, Opcode::from_u8(Opcode::OP_PUSHBYTES_62 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_63, Opcode::from_u8(Opcode::OP_PUSHBYTES_63 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_64, Opcode::from_u8(Opcode::OP_PUSHBYTES_64 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_65, Opcode::from_u8(Opcode::OP_PUSHBYTES_65 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_66, Opcode::from_u8(Opcode::OP_PUSHBYTES_66 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_67, Opcode::from_u8(Opcode::OP_PUSHBYTES_67 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_68, Opcode::from_u8(Opcode::OP_PUSHBYTES_68 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_69, Opcode::from_u8(Opcode::OP_PUSHBYTES_69 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_70, Opcode::from_u8(Opcode::OP_PUSHBYTES_70 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_71, Opcode::from_u8(Opcode::OP_PUSHBYTES_71 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_72, Opcode::from_u8(Opcode::OP_PUSHBYTES_72 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_73, Opcode::from_u8(Opcode::OP_PUSHBYTES_73 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_74, Opcode::from_u8(Opcode::OP_PUSHBYTES_74 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHBYTES_75, Opcode::from_u8(Opcode::OP_PUSHBYTES_75 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHDATA1, Opcode::from_u8(Opcode::OP_PUSHDATA1 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHDATA2, Opcode::from_u8(Opcode::OP_PUSHDATA2 as u8).unwrap()); - assert_eq!(Opcode::OP_PUSHDATA4, Opcode::from_u8(Opcode::OP_PUSHDATA4 as u8).unwrap()); - assert_eq!(Opcode::OP_1NEGATE, Opcode::from_u8(Opcode::OP_1NEGATE as u8).unwrap()); - assert_eq!(Opcode::OP_RESERVED, Opcode::from_u8(Opcode::OP_RESERVED as u8).unwrap()); - assert_eq!(Opcode::OP_1, Opcode::from_u8(Opcode::OP_1 as u8).unwrap()); - assert_eq!(Opcode::OP_2, Opcode::from_u8(Opcode::OP_2 as u8).unwrap()); - assert_eq!(Opcode::OP_3, Opcode::from_u8(Opcode::OP_3 as u8).unwrap()); - assert_eq!(Opcode::OP_4, Opcode::from_u8(Opcode::OP_4 as u8).unwrap()); - assert_eq!(Opcode::OP_5, Opcode::from_u8(Opcode::OP_5 as u8).unwrap()); - assert_eq!(Opcode::OP_6, Opcode::from_u8(Opcode::OP_6 as u8).unwrap()); - assert_eq!(Opcode::OP_7, Opcode::from_u8(Opcode::OP_7 as u8).unwrap()); - assert_eq!(Opcode::OP_8, Opcode::from_u8(Opcode::OP_8 as u8).unwrap()); - assert_eq!(Opcode::OP_9, Opcode::from_u8(Opcode::OP_9 as u8).unwrap()); - assert_eq!(Opcode::OP_10, Opcode::from_u8(Opcode::OP_10 as u8).unwrap()); - assert_eq!(Opcode::OP_11, Opcode::from_u8(Opcode::OP_11 as u8).unwrap()); - assert_eq!(Opcode::OP_12, Opcode::from_u8(Opcode::OP_12 as u8).unwrap()); - assert_eq!(Opcode::OP_13, Opcode::from_u8(Opcode::OP_13 as u8).unwrap()); - assert_eq!(Opcode::OP_14, Opcode::from_u8(Opcode::OP_14 as u8).unwrap()); - assert_eq!(Opcode::OP_15, Opcode::from_u8(Opcode::OP_15 as u8).unwrap()); - assert_eq!(Opcode::OP_16, Opcode::from_u8(Opcode::OP_16 as u8).unwrap()); - - // control - assert_eq!(Opcode::OP_NOP, Opcode::from_u8(Opcode::OP_NOP as u8).unwrap()); - assert_eq!(Opcode::OP_VER, Opcode::from_u8(Opcode::OP_VER as u8).unwrap()); - assert_eq!(Opcode::OP_IF, Opcode::from_u8(Opcode::OP_IF as u8).unwrap()); - assert_eq!(Opcode::OP_NOTIF, Opcode::from_u8(Opcode::OP_NOTIF as u8).unwrap()); - assert_eq!(Opcode::OP_VERIF, Opcode::from_u8(Opcode::OP_VERIF as u8).unwrap()); - assert_eq!(Opcode::OP_VERNOTIF, Opcode::from_u8(Opcode::OP_VERNOTIF as u8).unwrap()); - assert_eq!(Opcode::OP_ELSE, Opcode::from_u8(Opcode::OP_ELSE as u8).unwrap()); - assert_eq!(Opcode::OP_ENDIF, Opcode::from_u8(Opcode::OP_ENDIF as u8).unwrap()); - assert_eq!(Opcode::OP_VERIFY, Opcode::from_u8(Opcode::OP_VERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_RETURN, Opcode::from_u8(Opcode::OP_RETURN as u8).unwrap()); - - // stack ops - assert_eq!(Opcode::OP_TOALTSTACK, Opcode::from_u8(Opcode::OP_TOALTSTACK as u8).unwrap()); - assert_eq!(Opcode::OP_FROMALTSTACK, Opcode::from_u8(Opcode::OP_FROMALTSTACK as u8).unwrap()); - assert_eq!(Opcode::OP_2DROP, Opcode::from_u8(Opcode::OP_2DROP as u8).unwrap()); - assert_eq!(Opcode::OP_2DUP, Opcode::from_u8(Opcode::OP_2DUP as u8).unwrap()); - assert_eq!(Opcode::OP_3DUP, Opcode::from_u8(Opcode::OP_3DUP as u8).unwrap()); - assert_eq!(Opcode::OP_2OVER, Opcode::from_u8(Opcode::OP_2OVER as u8).unwrap()); - assert_eq!(Opcode::OP_2ROT, Opcode::from_u8(Opcode::OP_2ROT as u8).unwrap()); - assert_eq!(Opcode::OP_2SWAP, Opcode::from_u8(Opcode::OP_2SWAP as u8).unwrap()); - assert_eq!(Opcode::OP_IFDUP, Opcode::from_u8(Opcode::OP_IFDUP as u8).unwrap()); - assert_eq!(Opcode::OP_DEPTH, Opcode::from_u8(Opcode::OP_DEPTH as u8).unwrap()); - assert_eq!(Opcode::OP_DROP, Opcode::from_u8(Opcode::OP_DROP as u8).unwrap()); - assert_eq!(Opcode::OP_DUP, Opcode::from_u8(Opcode::OP_DUP as u8).unwrap()); - assert_eq!(Opcode::OP_NIP, Opcode::from_u8(Opcode::OP_NIP as u8).unwrap()); - assert_eq!(Opcode::OP_OVER, Opcode::from_u8(Opcode::OP_OVER as u8).unwrap()); - assert_eq!(Opcode::OP_PICK, Opcode::from_u8(Opcode::OP_PICK as u8).unwrap()); - assert_eq!(Opcode::OP_ROLL, Opcode::from_u8(Opcode::OP_ROLL as u8).unwrap()); - assert_eq!(Opcode::OP_ROT, Opcode::from_u8(Opcode::OP_ROT as u8).unwrap()); - assert_eq!(Opcode::OP_SWAP, Opcode::from_u8(Opcode::OP_SWAP as u8).unwrap()); - assert_eq!(Opcode::OP_TUCK, Opcode::from_u8(Opcode::OP_TUCK as u8).unwrap()); - - // splice ops - assert_eq!(Opcode::OP_CAT, Opcode::from_u8(Opcode::OP_CAT as u8).unwrap()); - assert_eq!(Opcode::OP_SUBSTR, Opcode::from_u8(Opcode::OP_SUBSTR as u8).unwrap()); - assert_eq!(Opcode::OP_LEFT, Opcode::from_u8(Opcode::OP_LEFT as u8).unwrap()); - assert_eq!(Opcode::OP_RIGHT, Opcode::from_u8(Opcode::OP_RIGHT as u8).unwrap()); - assert_eq!(Opcode::OP_SIZE, Opcode::from_u8(Opcode::OP_SIZE as u8).unwrap()); - - // bit logic - assert_eq!(Opcode::OP_INVERT, Opcode::from_u8(Opcode::OP_INVERT as u8).unwrap()); - assert_eq!(Opcode::OP_AND, Opcode::from_u8(Opcode::OP_AND as u8).unwrap()); - assert_eq!(Opcode::OP_OR, Opcode::from_u8(Opcode::OP_OR as u8).unwrap()); - assert_eq!(Opcode::OP_XOR, Opcode::from_u8(Opcode::OP_XOR as u8).unwrap()); - assert_eq!(Opcode::OP_EQUAL, Opcode::from_u8(Opcode::OP_EQUAL as u8).unwrap()); - assert_eq!(Opcode::OP_EQUALVERIFY, Opcode::from_u8(Opcode::OP_EQUALVERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_RESERVED1, Opcode::from_u8(Opcode::OP_RESERVED1 as u8).unwrap()); - assert_eq!(Opcode::OP_RESERVED2, Opcode::from_u8(Opcode::OP_RESERVED2 as u8).unwrap()); - - // numeric - assert_eq!(Opcode::OP_1ADD, Opcode::from_u8(Opcode::OP_1ADD as u8).unwrap()); - assert_eq!(Opcode::OP_1SUB, Opcode::from_u8(Opcode::OP_1SUB as u8).unwrap()); - assert_eq!(Opcode::OP_2MUL, Opcode::from_u8(Opcode::OP_2MUL as u8).unwrap()); - assert_eq!(Opcode::OP_2DIV, Opcode::from_u8(Opcode::OP_2DIV as u8).unwrap()); - assert_eq!(Opcode::OP_NEGATE, Opcode::from_u8(Opcode::OP_NEGATE as u8).unwrap()); - assert_eq!(Opcode::OP_ABS, Opcode::from_u8(Opcode::OP_ABS as u8).unwrap()); - assert_eq!(Opcode::OP_NOT, Opcode::from_u8(Opcode::OP_NOT as u8).unwrap()); - assert_eq!(Opcode::OP_0NOTEQUAL, Opcode::from_u8(Opcode::OP_0NOTEQUAL as u8).unwrap()); - - assert_eq!(Opcode::OP_ADD, Opcode::from_u8(Opcode::OP_ADD as u8).unwrap()); - assert_eq!(Opcode::OP_SUB, Opcode::from_u8(Opcode::OP_SUB as u8).unwrap()); - assert_eq!(Opcode::OP_MUL, Opcode::from_u8(Opcode::OP_MUL as u8).unwrap()); - assert_eq!(Opcode::OP_DIV, Opcode::from_u8(Opcode::OP_DIV as u8).unwrap()); - assert_eq!(Opcode::OP_MOD, Opcode::from_u8(Opcode::OP_MOD as u8).unwrap()); - assert_eq!(Opcode::OP_LSHIFT, Opcode::from_u8(Opcode::OP_LSHIFT as u8).unwrap()); - assert_eq!(Opcode::OP_RSHIFT, Opcode::from_u8(Opcode::OP_RSHIFT as u8).unwrap()); - - assert_eq!(Opcode::OP_BOOLAND, Opcode::from_u8(Opcode::OP_BOOLAND as u8).unwrap()); - assert_eq!(Opcode::OP_BOOLOR, Opcode::from_u8(Opcode::OP_BOOLOR as u8).unwrap()); - assert_eq!(Opcode::OP_NUMEQUAL, Opcode::from_u8(Opcode::OP_NUMEQUAL as u8).unwrap()); - assert_eq!(Opcode::OP_NUMEQUALVERIFY, Opcode::from_u8(Opcode::OP_NUMEQUALVERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_NUMNOTEQUAL, Opcode::from_u8(Opcode::OP_NUMNOTEQUAL as u8).unwrap()); - assert_eq!(Opcode::OP_LESSTHAN, Opcode::from_u8(Opcode::OP_LESSTHAN as u8).unwrap()); - assert_eq!(Opcode::OP_GREATERTHAN, Opcode::from_u8(Opcode::OP_GREATERTHAN as u8).unwrap()); - assert_eq!(Opcode::OP_LESSTHANOREQUAL, Opcode::from_u8(Opcode::OP_LESSTHANOREQUAL as u8).unwrap()); - assert_eq!(Opcode::OP_GREATERTHANOREQUAL, Opcode::from_u8(Opcode::OP_GREATERTHANOREQUAL as u8).unwrap()); - assert_eq!(Opcode::OP_MIN, Opcode::from_u8(Opcode::OP_MIN as u8).unwrap()); - assert_eq!(Opcode::OP_MAX, Opcode::from_u8(Opcode::OP_MAX as u8).unwrap()); - - assert_eq!(Opcode::OP_WITHIN, Opcode::from_u8(Opcode::OP_WITHIN as u8).unwrap()); - - // crypto - assert_eq!(Opcode::OP_RIPEMD160, Opcode::from_u8(Opcode::OP_RIPEMD160 as u8).unwrap()); - assert_eq!(Opcode::OP_SHA1, Opcode::from_u8(Opcode::OP_SHA1 as u8).unwrap()); - assert_eq!(Opcode::OP_SHA256, Opcode::from_u8(Opcode::OP_SHA256 as u8).unwrap()); - assert_eq!(Opcode::OP_HASH160, Opcode::from_u8(Opcode::OP_HASH160 as u8).unwrap()); - assert_eq!(Opcode::OP_HASH256, Opcode::from_u8(Opcode::OP_HASH256 as u8).unwrap()); - assert_eq!(Opcode::OP_CODESEPARATOR, Opcode::from_u8(Opcode::OP_CODESEPARATOR as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKSIG, Opcode::from_u8(Opcode::OP_CHECKSIG as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKSIGVERIFY, Opcode::from_u8(Opcode::OP_CHECKSIGVERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKMULTISIG, Opcode::from_u8(Opcode::OP_CHECKMULTISIG as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKMULTISIGVERIFY, Opcode::from_u8(Opcode::OP_CHECKMULTISIGVERIFY as u8).unwrap()); - - // expansion - assert_eq!(Opcode::OP_NOP1, Opcode::from_u8(Opcode::OP_NOP1 as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKLOCKTIMEVERIFY, Opcode::from_u8(Opcode::OP_CHECKLOCKTIMEVERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_CHECKSEQUENCEVERIFY, Opcode::from_u8(Opcode::OP_CHECKSEQUENCEVERIFY as u8).unwrap()); - assert_eq!(Opcode::OP_NOP4, Opcode::from_u8(Opcode::OP_NOP4 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP5, Opcode::from_u8(Opcode::OP_NOP5 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP6, Opcode::from_u8(Opcode::OP_NOP6 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP7, Opcode::from_u8(Opcode::OP_NOP7 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP8, Opcode::from_u8(Opcode::OP_NOP8 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP9, Opcode::from_u8(Opcode::OP_NOP9 as u8).unwrap()); - assert_eq!(Opcode::OP_NOP10, Opcode::from_u8(Opcode::OP_NOP10 as u8).unwrap()); - } -} diff --git a/cxrml/bridge/btc/src/script/script.rs b/cxrml/bridge/btc/src/script/script.rs deleted file mode 100644 index 7455849d3bb75..0000000000000 --- a/cxrml/bridge/btc/src/script/script.rs +++ /dev/null @@ -1,659 +0,0 @@ -//! Serialized script, used inside transaction inputs and outputs. - -#[cfg(feature = "std")] -use std::fmt; -use rstd::ops; -use super::bytes::Bytes; -use super::keys::{AddressHash, Public}; -use super::{Opcode, Error}; -use super::keys; - -/// Maximum number of public keys per multisig -pub const MAX_PUBKEYS_PER_MULTISIG: usize = 20; - -/// Classified script type -#[derive(PartialEq, Debug)] -pub enum ScriptType { - NonStandard, - PubKey, - PubKeyHash, - ScriptHash, - Multisig, - NullData, - WitnessScript, - WitnessKey, -} - -/// Address from Script -#[derive(PartialEq, Debug)] -pub struct ScriptAddress { - /// The type of the address. - pub kind: keys::Type, - /// Public key hash. - pub hash: AddressHash, -} - -impl<'a> From<&'a keys::Address> for ScriptAddress { - fn from(address: &'a keys::Address) -> Self { - match address.kind { - keys::Type::P2PKH => ScriptAddress::new_p2pkh(address.hash.clone()), - keys::Type::P2SH => ScriptAddress::new_p2sh(address.hash.clone()), - } - } -} - -impl ScriptAddress { - /// Creates P2PKH-type ScriptAddress - pub fn new_p2pkh(hash: AddressHash) -> Self { - ScriptAddress { - kind: keys::Type::P2PKH, - hash: hash, - } - } - - /// Creates P2SH-type ScriptAddress - pub fn new_p2sh(hash: AddressHash) -> Self { - ScriptAddress { - kind: keys::Type::P2SH, - hash: hash, - } - } -} - -/// Serialized script, used inside transaction inputs and outputs. -#[derive(PartialEq, Debug)] -pub struct Script { - data: Bytes, -} - -impl From<&'static str> for Script { - fn from(s: &'static str) -> Self { - Script::new(s.into()) - } -} - -impl From for Script { - fn from(s: Bytes) -> Self { - Script::new(s) - } -} - -impl From> for Script { - fn from(v: Vec) -> Self { - Script::new(v.into()) - } -} - -impl From