diff --git a/.bumpversion.cfg b/.bumpversion.cfg index ca0fb075..979a70d9 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -11,6 +11,10 @@ replace = version = "{new_version}" search = version = "{current_version}" replace = version = "{new_version}" +[bumpversion:file:traits/Cargo.toml] +search = version = "{current_version}" +replace = version = "{new_version}" + [bumpversion:file:docs/conf.py] search = release = "{current_version}" replace = release = "{new_version}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3ef17930..97590c50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,6 +30,7 @@ jobs: profile: minimal toolchain: nightly override: true - - run: cargo publish + - run: cargo install cargo-release + - run: cargo release --workspace --execute env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.gitignore b/.gitignore index c8f04429..7f5c2b46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/target +**/target +Cargo.lock # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 433ccfa7..bb43b505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Changelog -## [0.10.0] - Unreleased +## [0.10.0] - 2022-10-31 ### Changed - Use `pythonize` for jsonParsed values [(#20)](https://github.com/kevinheavey/solders/pull/20) +- Extract `solders-traits` into its own crate [(#21)](https://github.com/kevinheavey/solders/pull/21) ## [0.9.3] - 2022-10-15 diff --git a/Cargo.lock b/Cargo.lock index c9a1b819..0e5b4c6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,25 +8,25 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.8", "once_cell", "version_check", ] [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] [[package]] name = "anyhow" -version = "1.0.61" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "arrayref" @@ -71,9 +71,9 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bincode" @@ -110,7 +110,7 @@ dependencies = [ "cc", "cfg-if", "constant_time_eq", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -125,9 +125,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -191,9 +191,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "bv" @@ -207,18 +207,18 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44f8cb64b4147a528e1e9e77583739e683541973295b35f3bd7e78d42c5971fd" +checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339cdf1eb047d1c96cb8be64f4bc28975821222ec1736edfa06e140cf18d0064" +checksum = "1b9e1f5fa78f69496407a27ae9ed989e3c3b072310286f5ef385525e4cbc24a9" dependencies = [ "proc-macro2", "quote", @@ -239,9 +239,9 @@ checksum = "02d88a780e6aa14b75d7be99f374d8b5c315aaf9c12ada1e2b1cb281468584c9" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" dependencies = [ "jobserver", ] @@ -254,9 +254,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ "num-integer", "num-traits", @@ -296,18 +296,18 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if", "crossbeam-utils", @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -326,26 +326,24 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "lazy_static", "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "lazy_static", ] [[package]] @@ -356,9 +354,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-common" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", "typenum", @@ -464,11 +462,11 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.3", "crypto-common", "subtle", ] @@ -505,20 +503,20 @@ dependencies = [ "derivation-path", "ed25519-dalek", "hmac 0.12.1", - "sha2 0.10.2", + "sha2 0.10.6", ] [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "env_logger" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" dependencies = [ "atty", "humantime", @@ -541,9 +539,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "serde", "typenum", @@ -565,14 +563,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -625,7 +623,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -658,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" dependencies = [ "bitmaps", - "rand_core 0.6.3", + "rand_core 0.6.4", "rand_xoshiro", "rayon", "serde", @@ -669,39 +667,39 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05a0bd019339e5d968b37855180087b7b9d512c5046fbd244cf8c95687927d6e" +checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3" [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -720,9 +718,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libsecp256k1" @@ -774,9 +772,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -799,9 +797,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap2" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5172b50c23043ff43dd53e51392f36519d9b35a8f3a410d30ece5d1aedd58ae" +checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" dependencies = [ "libc", ] @@ -857,9 +855,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "opaque-debug" @@ -879,9 +877,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if", "libc", @@ -905,14 +903,14 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "ppv-lite86" @@ -931,18 +929,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f72538a0230791398a0986a6518ebd88abc3fded89007b506ed072acc831e1" +checksum = "201b6887e5576bf2f945fe65172c1fcbf3fcf285b23e4d71eb171d9736e38d32" dependencies = [ "cfg-if", "indoc", @@ -957,9 +955,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4cf18c20f4f09995f3554e6bcf9b09bd5e4d6b67c562fdfaafa644526ba479" +checksum = "bf0708c9ed01692635cbf056e286008e5a2927ab1a5e48cdd3aeb1ba5a6fef47" dependencies = [ "once_cell", "target-lexicon", @@ -967,9 +965,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41877f28d8ebd600b6aa21a17b40c3b0fc4dfe73a27b6e81ab3d895e401b0e9" +checksum = "90352dea4f486932b72ddf776264d293f85b79a1d214de1d023927b41461132d" dependencies = [ "libc", "pyo3-build-config", @@ -977,9 +975,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e81c8d4bcc2f216dc1b665412df35e46d12ee8d3d046b381aad05f1fcf30547" +checksum = "7eb24b804a2d9e88bfcc480a5a6dd76f006c1e3edaf064e8250423336e2cd79d" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -989,9 +987,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85752a767ee19399a78272cc2ab625cd7d373b2e112b4b13db28de71fa892784" +checksum = "f22bb49f6a7348c253d7ac67a6875f2dc65f36c2ae64a82c381d528972bea6d6" dependencies = [ "proc-macro2", "quote", @@ -1019,9 +1017,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.18" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -1060,11 +1058,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.8", ] [[package]] @@ -1082,7 +1080,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -1111,18 +1109,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -1131,9 +1129,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "rustc-hash" @@ -1158,9 +1156,9 @@ checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "scopeguard" @@ -1170,24 +1168,24 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "semver" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.138" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" +checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" dependencies = [ "serde", ] @@ -1204,9 +1202,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.138" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -1215,9 +1213,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -1261,30 +1259,30 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] name = "sha3" -version = "0.10.1" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86" +checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", "keccak", ] [[package]] name = "signature" -version = "1.5.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "sized-chunks" @@ -1298,15 +1296,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "solana-frozen-abi" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0435ad6b19ca941af55973ab3d4684773ffdbc96f421ed86fadf8af0c5f596f7" +checksum = "fae9453c906a52b00c6d668508214377163cf59776cfa8e09ef740a2a493f87d" dependencies = [ "ahash", "blake3", @@ -1324,13 +1322,13 @@ dependencies = [ "log", "memmap2", "once_cell", - "rand_core 0.6.3", + "rand_core 0.6.4", "rustc_version", "serde", "serde_bytes", "serde_derive", "serde_json", - "sha2 0.10.2", + "sha2 0.10.6", "solana-frozen-abi-macro", "subtle", "thiserror", @@ -1338,9 +1336,9 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba5fdc33a54211972556f1c887954f35641bd99a50af9b06164018ccd00c1bd3" +checksum = "e29cd0fef92aee046267cdd69d8aa8b31cd3549991ea6f2c6076b21064e235fb" dependencies = [ "proc-macro2", "quote", @@ -1350,9 +1348,9 @@ dependencies = [ [[package]] name = "solana-logger" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f25fe8523827c1fb1a0460a4141903b3451f7309b5bbaee70bec8e4d1a86f77" +checksum = "d255b73f0c0e1eaa34280094f1304a783ea9394dbf2f8b749a3661e948ca5551" dependencies = [ "env_logger", "lazy_static", @@ -1361,11 +1359,11 @@ dependencies = [ [[package]] name = "solana-program" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7476d699927533b3f2b4bcc08249d8e33c30a2c6b0144f5fa463b7f797689ccb" +checksum = "e0eeda17e271e11864d48b35eeaefed9591305b4d47266caf3f8b11b9271833d" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bincode", "bitflags", "blake3", @@ -1378,7 +1376,7 @@ dependencies = [ "console_error_panic_hook", "console_log", "curve25519-dalek", - "getrandom 0.2.6", + "getrandom 0.2.8", "itertools", "js-sys", "lazy_static", @@ -1397,7 +1395,7 @@ dependencies = [ "serde_bytes", "serde_derive", "serde_json", - "sha2 0.10.2", + "sha2 0.10.6", "sha3", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -1410,12 +1408,12 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42390ef4d93ff944bf6325be65474510165b8108b64b0d0076570ac7130bacc8" +checksum = "57fe62f7fe938607437ed29b0e95b4cffc7db186bf04fea6a98d92319da941b1" dependencies = [ "assert_matches", - "base64 0.13.0", + "base64 0.13.1", "bincode", "bitflags", "borsh", @@ -1424,7 +1422,7 @@ dependencies = [ "byteorder", "chrono", "derivation-path", - "digest 0.10.3", + "digest 0.10.5", "ed25519-dalek", "ed25519-dalek-bip32", "generic-array", @@ -1447,7 +1445,7 @@ dependencies = [ "serde_bytes", "serde_derive", "serde_json", - "sha2 0.10.2", + "sha2 0.10.6", "sha3", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -1461,9 +1459,9 @@ dependencies = [ [[package]] name = "solana-sdk-macro" -version = "1.14.1" +version = "1.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e1093561f2184d2eda7c593abe4428150c41cb8d70299b9746cb26240cfb4a" +checksum = "12f9abf0bdba679d93c5624043ae3dcbf529ed2251c281cc615fa55c8dc2f0bd" dependencies = [ "bs58", "proc-macro2", @@ -1476,7 +1474,7 @@ dependencies = [ name = "solders" version = "0.9.3" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bincode", "borsh", "bs58", @@ -1491,6 +1489,7 @@ dependencies = [ "serde_with", "solana-sdk", "solders-macros", + "solders-traits", "thiserror", "zstd", ] @@ -1506,6 +1505,18 @@ dependencies = [ "syn", ] +[[package]] +name = "solders-traits" +version = "0.9.3" +dependencies = [ + "bincode", + "pyo3", + "serde", + "serde_cbor", + "serde_json", + "solana-sdk", +] + [[package]] name = "strsim" version = "0.10.0" @@ -1520,9 +1531,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.99" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -1558,18 +1569,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -1627,30 +1638,30 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "unicode-xid" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unindent" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52fee519a3e570f7df377a06a1a7775cdbfb7aa460be7e08de2b1f0e69973a44" +checksum = "58ee9362deb4a96cef4d437d1ad49cffc9b9e92d202b6995674e928ce684f112" [[package]] name = "uriparse" @@ -1676,15 +1687,15 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1692,9 +1703,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1707,9 +1718,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1717,9 +1728,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1730,15 +1741,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -1777,46 +1788,60 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ + "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", + "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "zeroize" diff --git a/Cargo.toml b/Cargo.toml index d3d92a9e..617168b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,8 @@ bs58 = "^0.4.0" zstd = "0.11.2" derive_more = "0.99.17" pythonize = "0.17.0" +solders-traits = { path = "./traits", version = "0.9.3" } + + +[workspace] +members = [".", "traits"] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 84c392c1..289346a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ name = "solders" version = "0.9.3" description = "Python binding to the Solana Rust SDK" authors = [ {name = "kevinheavey", email = "kevinheavey123@gmail.com"} ] -license = {file = "LICENSE"} +license = {file = "LICENSE"} # relative to the package/ directory requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", diff --git a/src/account.rs b/src/account.rs index cc1746a5..0a837858 100644 --- a/src/account.rs +++ b/src/account.rs @@ -5,14 +5,15 @@ use pyo3::{prelude::*, types::PyBytes}; use serde::{Deserialize, Serialize}; use solana_sdk::{account::Account as AccountOriginal, clock::Epoch}; use solders_macros::{common_methods, richcmp_eq_only}; +use solders_traits::{ + impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, CommonMethods, + PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, +}; use crate::{ account_decoder::ParsedAccount, - impl_display, pubkey::Pubkey, - py_from_bytes_general_via_bincode, pybytes_general_via_bincode, tmp_account_decoder::{UiAccount, UiAccountData, UiAccountEncoding}, - CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, }; /// An Account with data that is stored on chain. diff --git a/src/account_decoder.rs b/src/account_decoder.rs index dc9994af..bcb5ebea 100644 --- a/src/account_decoder.rs +++ b/src/account_decoder.rs @@ -1,12 +1,12 @@ +use solders_traits::{ + handle_py_value_err, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, + CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, +}; use std::fmt::Display; -use crate::{ - handle_py_value_err, - tmp_account_decoder::{ - ParsedAccount as ParsedAccountOriginal, UiDataSliceConfig as UiDataSliceConfigOriginal, - UiTokenAmount as UiTokenAmountOriginal, - }, - CommonMethods, +use crate::tmp_account_decoder::{ + ParsedAccount as ParsedAccountOriginal, UiDataSliceConfig as UiDataSliceConfigOriginal, + UiTokenAmount as UiTokenAmountOriginal, }; use derive_more::{From, Into}; use pyo3::prelude::*; @@ -15,11 +15,6 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use solders_macros::{common_methods, richcmp_eq_only}; -use crate::{ - py_from_bytes_general_via_bincode, pybytes_general_via_bincode, PyBytesBincode, - PyFromBytesBincode, RichcmpEqualityOnly, -}; - /// Configuration object for limiting returned account data. /// /// Args: diff --git a/src/address_lookup_table_account.rs b/src/address_lookup_table_account.rs index ca9f6384..a78b9a8f 100644 --- a/src/address_lookup_table_account.rs +++ b/src/address_lookup_table_account.rs @@ -6,12 +6,13 @@ use solana_sdk::{ pubkey::Pubkey as PubkeyOriginal, }; use solders_macros::{common_methods, richcmp_eq_only}; - -use crate::{ - impl_display, pubkey::Pubkey, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, - CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, +use solders_traits::{ + impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, CommonMethods, + PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, }; +use crate::pubkey::Pubkey; + #[derive(Serialize, Deserialize)] #[serde(remote = "AddressLookupTableAccountOriginal")] struct AddressLookupTableAccountOriginalDef { diff --git a/src/commitment_config.rs b/src/commitment_config.rs index aca15971..62fb0c54 100644 --- a/src/commitment_config.rs +++ b/src/commitment_config.rs @@ -1,27 +1,13 @@ use std::str::FromStr; use derive_more::{From, Into}; -use pyo3::{create_exception, exceptions::PyException, prelude::*}; +use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use solana_sdk::commitment_config::{ CommitmentConfig as CommitmentConfigOriginal, CommitmentLevel as CommitmentLevelOriginal, - ParseCommitmentLevelError as ParseCommitmentLevelErrorOriginal, }; -use crate::{handle_py_err, PyErrWrapper}; - -create_exception!( - solders, - ParseCommitmentLevelError, - PyException, - "Raised when an error is encountered converting a string into a ``CommitmentConfig``." -); - -impl From for PyErrWrapper { - fn from(e: ParseCommitmentLevelErrorOriginal) -> Self { - Self(ParseCommitmentLevelError::new_err(e.to_string())) - } -} +use solders_traits::{handle_py_err}; /// RPC request `commitment `_ options. #[pyclass(module = "solders.commitment_config")] diff --git a/src/epoch_schedule.rs b/src/epoch_schedule.rs index 6bf53e7f..04c49585 100644 --- a/src/epoch_schedule.rs +++ b/src/epoch_schedule.rs @@ -7,7 +7,7 @@ use solana_sdk::{ }; use solders_macros::{common_methods, richcmp_eq_only}; -use crate::{ +use solders_traits::{ impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, }; diff --git a/src/hash.rs b/src/hash.rs index ccdd1f95..a27f36f0 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,31 +1,18 @@ use std::str::FromStr; use derive_more::{From, Into}; -use pyo3::{create_exception, exceptions::PyException, prelude::*}; +use pyo3::{prelude::*}; use serde::{Deserialize, Serialize}; use solana_sdk::hash::{ hash, Hash as HashOriginal, ParseHashError as ParseHashErrorOriginal, HASH_BYTES, }; use solders_macros::{common_methods, pyhash, richcmp_full}; -use crate::{ +use solders_traits::{ handle_py_err, impl_display, pybytes_general_via_slice, CommonMethods, PyBytesSlice, - PyErrWrapper, PyFromBytesGeneral, PyHash, RichcmpFull, + PyFromBytesGeneral, PyHash, RichcmpFull, }; -create_exception!( - solders, - ParseHashError, - PyException, - "Raised when an error is encountered converting a string into a ``Hash``." -); - -impl From for PyErrWrapper { - fn from(e: ParseHashErrorOriginal) -> Self { - Self(ParseHashError::new_err(e.to_string())) - } -} - #[pyclass(module = "solders.hash", subclass)] /// A SHA-256 hash, most commonly used for blockhashes. /// diff --git a/src/instruction.rs b/src/instruction.rs index 90b448de..cfd48ce6 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -11,9 +11,10 @@ use solana_sdk::{ pubkey::Pubkey as PubkeyOriginal, }; use solders_macros::{common_methods, pyhash, richcmp_eq_only}; +use crate::pubkey::Pubkey; -use crate::{ - impl_display, pubkey::Pubkey, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, +use solders_traits::{ + impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, CommonMethods, PyBytesBincode, PyFromBytesBincode, PyHash, RichcmpEqualityOnly, }; diff --git a/src/keypair.rs b/src/keypair.rs index f33773d5..5e8b9dec 100644 --- a/src/keypair.rs +++ b/src/keypair.rs @@ -1,3 +1,4 @@ +use crate::{pubkey::Pubkey, signature::Signature}; use derive_more::{From, Into}; use pyo3::{prelude::*, types::PyBytes}; use serde::{Deserialize, Serialize}; @@ -9,10 +10,9 @@ use solana_sdk::signer::{ }; use solders_macros::{common_methods, pyhash, richcmp_signer}; -use crate::{ - handle_py_value_err, impl_display, impl_signer_hash, pubkey::Pubkey, signature::Signature, - CommonMethods, PyBytesGeneral, PyFromBytesGeneral, PyHash, RichcmpSigner, SignerTraitWrapper, - ToSignerOriginal, +use solders_traits::{ + handle_py_value_err, impl_display, impl_signer_hash, CommonMethods, PyBytesGeneral, + PyFromBytesGeneral, PyHash, RichcmpSigner, SignerTraitWrapper, ToSignerOriginal, }; mod keypair_serde { diff --git a/src/lib.rs b/src/lib.rs index df2269dc..61af31d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,35 +3,21 @@ //! If you're viewing them on docs.rs, the formatting won't make much sense. use account::create_account_mod; use address_lookup_table_account::create_address_lookup_table_account_mod; -use bincode::ErrorKind; use commitment_config::{CommitmentConfig, CommitmentLevel}; -use pyo3::{ - create_exception, - exceptions::{PyException, PyTypeError, PyValueError}, - prelude::*, - pyclass::CompareOp, - types::PyBytes, -}; -use rpc::{create_rpc_mod, requests::SerdeJSONError}; -use serde::{Deserialize, Serialize}; +use pyo3::prelude::*; +use rpc::create_rpc_mod; use solana_sdk::{ - instruction::Instruction as InstructionOriginal, - pubkey::Pubkey as PubkeyOriginal, - signature::Signature as SignatureOriginal, - signer::{Signer as SignerTrait, SignerError as SignerErrorOriginal}, -}; -use std::{ - collections::{hash_map::DefaultHasher, HashMap}, - fmt, - hash::{Hash, Hasher}, + instruction::Instruction as InstructionOriginal, pubkey::Pubkey as PubkeyOriginal, }; +use solders_traits::{BincodeError, CborError, ParseHashError, SerdeJSONError, SignerError}; +use std::collections::HashMap; use system_program::create_system_program_mod; use sysvar::create_sysvar_mod; use transaction_status::create_transaction_status_mod; pub mod pubkey; use pubkey::Pubkey; pub mod signer; -use signer::{Signer, SignerError}; +use signer::{Signer}; pub mod signature; use signature::Signature; pub mod keypair; @@ -39,7 +25,7 @@ use keypair::Keypair; pub mod instruction; use instruction::{AccountMeta, CompiledInstruction, Instruction}; pub mod hash; -use hash::{Hash as SolderHash, ParseHashError}; +use hash::Hash as SolderHash; pub mod message; use message::create_message_mod; pub mod transaction; @@ -62,59 +48,6 @@ mod tmp_transaction_status; pub mod transaction_status; use epoch_schedule::create_epoch_schedule_mod; -struct PyErrWrapper(PyErr); - -impl From for PyErr { - fn from(e: PyErrWrapper) -> Self { - e.0 - } -} - -fn to_py_err>(e: T) -> PyErr { - let wrapped: PyErrWrapper = e.into(); - wrapped.into() -} - -fn handle_py_err, E: ToString + Into, P>( - res: Result, -) -> PyResult

{ - res.map_or_else(|e| Err(to_py_err(e)), |v| Ok(v.into())) -} - -fn to_py_value_err(err: &impl ToString) -> PyErr { - PyValueError::new_err(err.to_string()) -} - -fn handle_py_value_err, E: ToString, P>(res: Result) -> PyResult

{ - res.map_or_else(|e| Err(to_py_value_err(&e)), |v| Ok(v.into())) -} - -create_exception!( - solders, - BincodeError, - PyException, - "Raised when the Rust bincode library returns an error during (de)serialization." -); - -create_exception!( - solders, - CborError, - PyException, - "Raised when the Rust cbor library returns an error during (de)serialization." -); - -impl From> for PyErrWrapper { - fn from(e: Box) -> Self { - Self(BincodeError::new_err(e.to_string())) - } -} - -impl From for PyErrWrapper { - fn from(e: serde_cbor::Error) -> Self { - Self(CborError::new_err(e.to_string())) - } -} - fn convert_optional_pubkey(pubkey: Option<&Pubkey>) -> Option<&PubkeyOriginal> { pubkey.map(|p| p.as_ref()) } @@ -126,302 +59,6 @@ fn convert_instructions(instructions: Vec) -> Vec PyErr { - let msg = format!("{op} not supported."); - PyTypeError::new_err(msg) -} - -fn calculate_hash(t: &T) -> u64 -where - T: Hash + ?Sized, -{ - let mut s = DefaultHasher::new(); - t.hash(&mut s); - s.finish() -} - -pub trait ToSignerOriginal { - fn to_inner(&self) -> Box; -} - -pub trait SignerTraitWrapper: ToSignerOriginal { - fn pubkey(&self) -> PubkeyOriginal { - self.to_inner().pubkey() - } - fn try_pubkey(&self) -> Result { - self.to_inner().try_pubkey() - } - fn sign_message(&self, message: &[u8]) -> SignatureOriginal { - self.to_inner().sign_message(message) - } - fn try_sign_message(&self, message: &[u8]) -> Result { - self.to_inner().try_sign_message(message) - } - fn is_interactive(&self) -> bool { - self.to_inner().is_interactive() - } -} - -pub trait RichcmpEqualityOnly: PartialEq { - fn richcmp(&self, other: &Self, op: CompareOp) -> PyResult { - match op { - CompareOp::Eq => Ok(self == other), - CompareOp::Ne => Ok(self != other), - CompareOp::Lt => Err(richcmp_type_error("<")), - CompareOp::Gt => Err(richcmp_type_error(">")), - CompareOp::Le => Err(richcmp_type_error("<=")), - CompareOp::Ge => Err(richcmp_type_error(">=")), - } - } -} - -pub trait RichcmpSigner: SignerTraitWrapper { - fn richcmp(&self, other: impl SignerTraitWrapper, op: CompareOp) -> PyResult { - let eq_val = self.pubkey() == other.pubkey(); - match op { - CompareOp::Eq => Ok(eq_val), - CompareOp::Ne => Ok(!eq_val), - CompareOp::Lt => Err(richcmp_type_error("<")), - CompareOp::Gt => Err(richcmp_type_error(">")), - CompareOp::Le => Err(richcmp_type_error("<=")), - CompareOp::Ge => Err(richcmp_type_error(">=")), - } - } -} - -pub trait RichcmpFull: PartialEq + PartialOrd { - fn richcmp(&self, other: &Self, op: CompareOp) -> bool { - match op { - CompareOp::Eq => self == other, - CompareOp::Ne => self != other, - CompareOp::Lt => self < other, - CompareOp::Gt => self > other, - CompareOp::Le => self <= other, - CompareOp::Ge => self >= other, - } - } -} - -macro_rules! impl_display { - ($ident:ident) => { - impl std::fmt::Display for $ident { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - }; -} - -pub(crate) use impl_display; - -macro_rules! impl_signer_hash { - ($ident:ident) => { - #[allow(clippy::derive_hash_xor_eq)] - impl std::hash::Hash for $ident { - fn hash(&self, state: &mut H) { - self.pubkey().hash(state); - } - } - }; -} - -pub(crate) use impl_signer_hash; -pub trait PyHash: Hash { - fn pyhash(&self) -> u64 { - calculate_hash(self) - } -} - -pub trait PyBytesSlice: AsRef<[u8]> { - fn pybytes_slice<'a>(&self, py: Python<'a>) -> &'a PyBytes { - PyBytes::new(py, self.as_ref()) - } -} - -macro_rules! pybytes_general_for_pybytes_slice { - ($ident:ident) => { - impl crate::PyBytesGeneral for $ident { - fn pybytes_general<'a>( - &self, - py: pyo3::prelude::Python<'a>, - ) -> &'a pyo3::types::PyBytes { - self.pybytes_slice(py) - } - } - }; -} - -pub(crate) use pybytes_general_for_pybytes_slice; - -macro_rules! pybytes_general_for_pybytes_bincode { - ($ident:ident) => { - impl crate::PyBytesGeneral for $ident { - fn pybytes_general<'a>( - &self, - py: pyo3::prelude::Python<'a>, - ) -> &'a pyo3::types::PyBytes { - self.pybytes_bincode(py) - } - } - }; -} - -pub(crate) use pybytes_general_for_pybytes_bincode; - -macro_rules! pybytes_general_for_pybytes_cbor { - ($ident:ident) => { - impl crate::PyBytesGeneral for $ident { - fn pybytes_general<'a>( - &self, - py: pyo3::prelude::Python<'a>, - ) -> &'a pyo3::types::PyBytes { - self.pybytes_cbor(py) - } - } - }; -} -pub(crate) use pybytes_general_for_pybytes_cbor; - -pub trait PyBytesBincode: Serialize { - fn pybytes_bincode<'a>(&self, py: Python<'a>) -> &'a PyBytes { - PyBytes::new(py, &bincode::serialize(self).unwrap()) - } -} - -pub trait PyBytesCbor: Serialize + std::marker::Sized { - fn pybytes_cbor<'a>(&self, py: Python<'a>) -> &'a PyBytes { - PyBytes::new(py, &serde_cbor::to_vec(self).unwrap()) - } -} - -pub trait PyBytesGeneral { - fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes; -} - -macro_rules! pybytes_general_via_slice { - ($ident:ident) => { - impl crate::PyBytesSlice for $ident {} - crate::pybytes_general_for_pybytes_slice!($ident); - }; -} - -pub(crate) use pybytes_general_via_slice; - -macro_rules! pybytes_general_via_bincode { - ($ident:ident) => { - impl crate::PyBytesBincode for $ident {} - crate::pybytes_general_for_pybytes_bincode!($ident); - }; -} -pub(crate) use pybytes_general_via_bincode; - -macro_rules! pybytes_general_via_cbor { - ($ident:ident) => { - impl crate::PyBytesCbor for $ident {} - crate::pybytes_general_for_pybytes_cbor!($ident); - }; -} -pub(crate) use pybytes_general_via_cbor; - -macro_rules! py_from_bytes_general_for_py_from_bytes_bincode { - ($ident:ident) => { - impl crate::PyFromBytesGeneral for $ident { - fn py_from_bytes_general(raw: &[u8]) -> PyResult { - Self::py_from_bytes_bincode(raw) - } - } - }; -} -pub(crate) use py_from_bytes_general_for_py_from_bytes_bincode; - -macro_rules! py_from_bytes_general_for_py_from_bytes_cbor { - ($ident:ident) => { - impl crate::PyFromBytesGeneral for $ident { - fn py_from_bytes_general(raw: &[u8]) -> PyResult { - Self::py_from_bytes_cbor(raw) - } - } - }; -} -pub(crate) use py_from_bytes_general_for_py_from_bytes_cbor; - -macro_rules! py_from_bytes_general_via_bincode { - ($ident:ident) => { - impl crate::PyFromBytesBincode<'_> for $ident {} - crate::py_from_bytes_general_for_py_from_bytes_bincode!($ident); - }; -} - -pub(crate) use py_from_bytes_general_via_bincode; -pub trait PyFromBytesBincode<'b>: Deserialize<'b> { - fn py_from_bytes_bincode(raw: &'b [u8]) -> PyResult { - let deser = bincode::deserialize::(raw); - handle_py_err(deser) - } -} - -macro_rules! py_from_bytes_general_via_cbor { - ($ident:ident) => { - impl crate::PyFromBytesCbor<'_> for $ident {} - crate::py_from_bytes_general_for_py_from_bytes_cbor!($ident); - }; -} - -pub(crate) use py_from_bytes_general_via_cbor; - -pub trait PyFromBytesCbor<'b>: Deserialize<'b> { - fn py_from_bytes_cbor(raw: &'b [u8]) -> PyResult { - let deser = serde_cbor::from_slice::(raw); - handle_py_err(deser) - } -} - -pub trait PyFromBytesGeneral: Sized { - fn py_from_bytes_general(raw: &[u8]) -> PyResult; -} - -pub trait CommonMethods<'a>: - fmt::Display - + fmt::Debug - + PyBytesGeneral - + PyFromBytesGeneral - + IntoPy - + Clone - + Serialize - + Deserialize<'a> -{ - fn pybytes<'b>(&self, py: Python<'b>) -> &'b PyBytes { - self.pybytes_general(py) - } - - fn pystr(&self) -> String { - self.to_string() - } - fn pyrepr(&self) -> String { - format!("{self:#?}") - } - - fn py_from_bytes(raw: &[u8]) -> PyResult { - Self::py_from_bytes_general(raw) - } - - fn pyreduce(&self) -> PyResult<(PyObject, PyObject)> { - let cloned = self.clone(); - Python::with_gil(|py| { - let constructor = cloned.into_py(py).getattr(py, "from_bytes")?; - Ok((constructor, (self.pybytes(py).to_object(py),).to_object(py))) - }) - } - - fn py_to_json(&self) -> String { - serde_json::to_string(self).unwrap() - } - - fn py_from_json(raw: &'a str) -> PyResult { - serde_json::from_str(raw).map_err(to_py_err) - } -} - /// A Python module implemented in Rust. #[pymodule] fn solders(py: Python, m: &PyModule) -> PyResult<()> { diff --git a/src/message.rs b/src/message.rs index e15bf11d..3de684b8 100644 --- a/src/message.rs +++ b/src/message.rs @@ -18,13 +18,15 @@ use solana_sdk::{ pubkey::Pubkey as PubkeyOriginal, }; use solders_macros::{common_methods, richcmp_eq_only}; +use solders_traits::{ + handle_py_err, impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, + CommonMethods, PyBytesBincode, PyBytesGeneral, PyErrWrapper, PyFromBytesBincode, + RichcmpEqualityOnly, +}; use crate::{ address_lookup_table_account::AddressLookupTableAccount, convert_instructions, - convert_optional_pubkey, handle_py_err, impl_display, py_from_bytes_general_via_bincode, - pybytes_general_via_bincode, CommonMethods, CompiledInstruction, Instruction, Pubkey, - PyBytesBincode, PyBytesGeneral, PyErrWrapper, PyFromBytesBincode, RichcmpEqualityOnly, - SolderHash, + convert_optional_pubkey, CompiledInstruction, Instruction, Pubkey, SolderHash, }; #[pyclass(module = "solders.message", subclass)] diff --git a/src/null_signer.rs b/src/null_signer.rs index cdddab1f..de8c7fed 100644 --- a/src/null_signer.rs +++ b/src/null_signer.rs @@ -1,12 +1,13 @@ +use crate::{Pubkey, Signature}; use derive_more::{From, Into}; use pyo3::{prelude::*, types::PyBytes}; use serde::{Deserialize, Serialize}; use solana_sdk::signer::{null_signer::NullSigner as NullSignerOriginal, Signer as SignerTrait}; use solders_macros::{common_methods, pyhash, richcmp_signer}; -use crate::{ - impl_display, impl_signer_hash, CommonMethods, Pubkey, PyBytesGeneral, PyFromBytesGeneral, - PyHash, RichcmpSigner, Signature, SignerTraitWrapper, ToSignerOriginal, +use solders_traits::{ + impl_display, impl_signer_hash, CommonMethods, PyBytesGeneral, PyFromBytesGeneral, PyHash, + RichcmpSigner, SignerTraitWrapper, ToSignerOriginal, }; mod null_signer_serde { diff --git a/src/presigner.rs b/src/presigner.rs index 27c66ef6..28f04452 100644 --- a/src/presigner.rs +++ b/src/presigner.rs @@ -1,9 +1,10 @@ use pyo3::prelude::*; use solana_sdk::signer::{presigner::Presigner as PresignerOriginal, Signer as SignerTrait}; use solders_macros::{pyhash, richcmp_signer}; +use crate::{Pubkey, Signature}; -use crate::{ - handle_py_err, impl_display, impl_signer_hash, Pubkey, PyHash, RichcmpSigner, Signature, +use solders_traits::{ + handle_py_err, impl_display, impl_signer_hash, PyHash, RichcmpSigner, SignerTraitWrapper, ToSignerOriginal, }; diff --git a/src/pubkey.rs b/src/pubkey.rs index cd590adc..d19b75ad 100644 --- a/src/pubkey.rs +++ b/src/pubkey.rs @@ -1,29 +1,18 @@ use std::{hash::Hash, str::FromStr}; -use crate::{ +use solders_traits::{ handle_py_err, handle_py_value_err, pybytes_general_via_slice, CommonMethods, PyBytesSlice, - PyErrWrapper, PyFromBytesGeneral, PyHash, RichcmpFull, + PyFromBytesGeneral, PyHash, RichcmpFull, }; use derive_more::{From, Into}; -use pyo3::{create_exception, exceptions::PyException, prelude::*}; +use pyo3::{prelude::*}; use serde::{Deserialize, Serialize}; use solana_sdk::pubkey::{ - ParsePubkeyError, Pubkey as PubkeyOriginal, PubkeyError as PubkeyErrorOriginal, PUBKEY_BYTES, + ParsePubkeyError, Pubkey as PubkeyOriginal, PUBKEY_BYTES, }; use solders_macros::{common_methods, pyhash, richcmp_full}; -create_exception!( - solders, - PubkeyError, - PyException, - "Umbrella error for the ``Pubkey`` object." -); -impl From for PyErrWrapper { - fn from(e: PubkeyErrorOriginal) -> Self { - Self(PubkeyError::new_err(e.to_string())) - } -} /// A public key. /// /// Args: diff --git a/src/rpc/config.rs b/src/rpc/config.rs index 59c240c6..2c34f43e 100644 --- a/src/rpc/config.rs +++ b/src/rpc/config.rs @@ -5,14 +5,17 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use solana_sdk::commitment_config::CommitmentLevel as CommitmentLevelOriginal; use solders_macros::{common_methods, richcmp_eq_only}; +use solders_traits::{ + impl_display, py_from_bytes_general_via_cbor, pybytes_general_via_cbor, CommonMethods, + PyBytesCbor, PyFromBytesCbor, RichcmpEqualityOnly, +}; use crate::{ account_decoder::{UiAccountEncoding, UiDataSliceConfig}, commitment_config::CommitmentLevel, hash::Hash as SolderHash, - impl_display, py_from_bytes_general_via_cbor, pybytes_general_via_cbor, transaction_status::{TransactionDetails, UiTransactionEncoding}, - CommonMethods, Pubkey, PyBytesCbor, PyFromBytesCbor, RichcmpEqualityOnly, Signature, + Pubkey, Signature, }; use super::filter::RpcFilterType; diff --git a/src/rpc/errors.rs b/src/rpc/errors.rs index 37372545..386cdece 100644 --- a/src/rpc/errors.rs +++ b/src/rpc/errors.rs @@ -1,7 +1,8 @@ use crate::{ transaction_status::{transaction_status_boilerplate, TransactionErrorType}, - CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, + }; +use solders_traits::{CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly,}; use derive_more::{From, Into}; use pyo3::{prelude::*, types::PyTuple, PyTypeInfo}; use serde::{Deserialize, Serialize}; diff --git a/src/rpc/filter.rs b/src/rpc/filter.rs index 9969234e..0a4e3df9 100644 --- a/src/rpc/filter.rs +++ b/src/rpc/filter.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use derive_more::{From, Into}; use solders_macros::{common_methods, enum_original_mapping, richcmp_eq_only}; -use crate::{ +use solders_traits::{ impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, }; diff --git a/src/rpc/requests.rs b/src/rpc/requests.rs index e73227d0..88d27521 100644 --- a/src/rpc/requests.rs +++ b/src/rpc/requests.rs @@ -2,16 +2,13 @@ use crate::{ commitment_config::{CommitmentConfig, CommitmentLevel}, message::Message, - py_from_bytes_general_via_cbor, pybytes_general_via_cbor, to_py_err, transaction::Transaction, - CommonMethods, Pubkey, PyBytesCbor, PyErrWrapper, PyFromBytesCbor, RichcmpEqualityOnly, + Pubkey, }; -use pyo3::{ - create_exception, - exceptions::{PyException, PyValueError}, - prelude::*, - types::PyTuple, - PyTypeInfo, +use pyo3::{exceptions::PyValueError, prelude::*, types::PyTuple, PyTypeInfo}; +use solders_traits::{ + py_from_bytes_general_via_cbor, pybytes_general_via_cbor, to_py_err, CommonMethods, + PyBytesCbor, PyFromBytesCbor, RichcmpEqualityOnly, }; extern crate base64; use crate::rpc::tmp_config::{ @@ -37,13 +34,6 @@ use super::config::{ TransactionLogsFilterWrapper, }; -create_exception!( - solders, - SerdeJSONError, - PyException, - "Raised when an error is encountered during JSON (de)serialization." -); - macro_rules! rpc_impl_display { ($ident:ident) => { impl std::fmt::Display for $ident { @@ -179,12 +169,6 @@ unsubscribe_def!(SlotsUpdatesUnsubscribe); unsubscribe_def!(RootUnsubscribe); unsubscribe_def!(VoteUnsubscribe); -impl From for PyErrWrapper { - fn from(e: serde_json::Error) -> Self { - Self(SerdeJSONError::new_err(e.to_string())) - } -} - #[derive(Deserialize, Serialize, PartialEq, Eq, Clone, Debug, Default)] pub enum V2 { #[default] diff --git a/src/rpc/responses.rs b/src/rpc/responses.rs index 84f14835..1309c095 100644 --- a/src/rpc/responses.rs +++ b/src/rpc/responses.rs @@ -57,18 +57,20 @@ use crate::transaction_status::{ use crate::{ account::{Account, AccountJSON}, pubkey::Pubkey, - py_from_bytes_general_via_bincode, pybytes_general_via_bincode, signature::Signature, tmp_account_decoder::{UiAccount, UiAccountData, UiTokenAmount as UiTokenAmountOriginal}, tmp_transaction_status::{ TransactionConfirmationStatus as TransactionConfirmationStatusOriginal, TransactionStatus as TransactionStatusOriginal, UiTransactionReturnData, }, - to_py_err, transaction_status::UiConfirmedBlock, - CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, SolderHash, + SolderHash, }; use camelpaste::paste; +use solders_traits::{ + py_from_bytes_general_via_bincode, pybytes_general_via_bincode, to_py_err, CommonMethods, + PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, +}; use super::errors::{ BlockCleanedUpMessage, BlockNotAvailableMessage, BlockStatusNotAvailableYetMessage, diff --git a/src/signature.rs b/src/signature.rs index 7d15d965..077a6914 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -5,9 +5,10 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use solana_sdk::signature::{ParseSignatureError, Signature as SignatureOriginal, SIGNATURE_BYTES}; use solders_macros::{common_methods, pyhash, richcmp_full}; +use crate::Pubkey; -use crate::{ - handle_py_value_err, impl_display, pybytes_general_via_slice, CommonMethods, Pubkey, +use solders_traits::{ + handle_py_value_err, impl_display, pybytes_general_via_slice, CommonMethods, PyBytesSlice, PyFromBytesGeneral, PyHash, RichcmpFull, }; diff --git a/src/signer.rs b/src/signer.rs index 3af7de78..e432e317 100644 --- a/src/signer.rs +++ b/src/signer.rs @@ -1,25 +1,13 @@ -use pyo3::{create_exception, exceptions::PyException, prelude::*}; +use pyo3::prelude::*; use solana_sdk::{ pubkey::Pubkey as PubkeyOriginal, signature::Signature as SignatureOriginal, signer::{signers::Signers, Signer as SignerTrait, SignerError as SignerErrorOriginal}, }; +use solders_traits::{SignerTraitWrapper, ToSignerOriginal}; -use crate::{Keypair, NullSigner, Presigner, PyErrWrapper, SignerTraitWrapper, ToSignerOriginal}; - -create_exception!( - solders, - SignerError, - PyException, - "Raised when an error is encountered during transaction signing." -); - -impl From for PyErrWrapper { - fn from(e: SignerErrorOriginal) -> Self { - Self(SignerError::new_err(e.to_string())) - } -} +use crate::{Keypair, NullSigner, Presigner}; #[derive(FromPyObject, Debug)] pub enum Signer { diff --git a/src/system_program.rs b/src/system_program.rs index fdd27f7f..95579a00 100644 --- a/src/system_program.rs +++ b/src/system_program.rs @@ -19,8 +19,9 @@ use solana_sdk::{ }, system_program, }; +use solders_traits::handle_py_err; -use crate::{handle_py_err, Instruction, Pubkey}; +use crate::{Instruction, Pubkey}; fn convert_instructions_from_original(ixs: Vec) -> Vec { ixs.into_iter().map(Instruction::from).collect() diff --git a/src/transaction.rs b/src/transaction.rs index c719e88f..dc1c7ae2 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -1,8 +1,6 @@ #![allow(deprecated)] use derive_more::{From, Into}; use pyo3::{ - create_exception, - exceptions::PyException, prelude::*, types::{PyBytes, PyInt, PyTuple}, PyTypeInfo, @@ -10,52 +8,28 @@ use pyo3::{ use serde::{Deserialize, Serialize}; use solana_sdk::{ pubkey::Pubkey as PubkeyOriginal, - sanitize::{Sanitize, SanitizeError as SanitizeErrorOriginal}, + sanitize::Sanitize, signature::Signature as SignatureOriginal, transaction::{ get_nonce_pubkey_from_instruction, uses_durable_nonce, Legacy as LegacyOriginal, - Transaction as TransactionOriginal, TransactionError as TransactionErrorOriginal, - TransactionVersion as TransactionVersionOriginal, + Transaction as TransactionOriginal, TransactionVersion as TransactionVersionOriginal, VersionedTransaction as VersionedTransactionOriginal, }, }; use solders_macros::{common_methods, richcmp_eq_only}; +use solders_traits::{ + handle_py_err, impl_display, py_from_bytes_general_via_bincode, pybytes_general_via_bincode, + CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, SanitizeError, + TransactionError, +}; use crate::{ - convert_instructions, convert_optional_pubkey, handle_py_err, impl_display, + convert_instructions, convert_optional_pubkey, message::{Message, VersionedMessage}, - py_from_bytes_general_via_bincode, pybytes_general_via_bincode, signer::SignerVec, - CommonMethods, CompiledInstruction, Instruction, Pubkey, PyBytesBincode, PyErrWrapper, - PyFromBytesBincode, RichcmpEqualityOnly, Signature, Signer, SolderHash, + CompiledInstruction, Instruction, Pubkey, Signature, Signer, SolderHash, }; -create_exception!( - solders, - TransactionError, - PyException, - "Umbrella error for the ``Transaction`` object." -); - -impl From for PyErrWrapper { - fn from(e: TransactionErrorOriginal) -> Self { - Self(TransactionError::new_err(e.to_string())) - } -} - -create_exception!( - solders, - SanitizeError, - PyException, - "Raised when an error is encountered during transaction sanitization." -); - -impl From for PyErrWrapper { - fn from(e: SanitizeErrorOriginal) -> Self { - Self(SanitizeError::new_err(e.to_string())) - } -} - /// An atomic transaction /// /// The ``__init__`` method signs a versioned message to diff --git a/src/transaction_status.rs b/src/transaction_status.rs index d7f524da..beac8063 100644 --- a/src/transaction_status.rs +++ b/src/transaction_status.rs @@ -2,13 +2,15 @@ use derive_more::{From, Into}; extern crate base64; use pythonize::{depythonize, pythonize}; +use solders_traits::{ + handle_py_value_err, CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, +}; use std::fmt::Display; use std::str::FromStr; use crate::{ account_decoder::UiTokenAmount, commitment_config::CommitmentConfig, - handle_py_value_err, message::MessageHeader, pubkey::Pubkey, signature::Signature, @@ -34,7 +36,7 @@ use crate::{ UiTransactionTokenBalance as UiTransactionTokenBalanceOriginal, }, transaction::{TransactionVersion, VersionedTransaction}, - CommonMethods, PyBytesBincode, PyFromBytesBincode, RichcmpEqualityOnly, SolderHash, + SolderHash, }; use pyo3::{ prelude::*, @@ -58,8 +60,8 @@ macro_rules! transaction_status_boilerplate { write!(f, "{:?}", self) } } - crate::pybytes_general_via_bincode!($name); - crate::py_from_bytes_general_via_bincode!($name); + solders_traits::pybytes_general_via_bincode!($name); + solders_traits::py_from_bytes_general_via_bincode!($name); impl<'a> CommonMethods<'a> for $name {} }; } diff --git a/traits/Cargo.toml b/traits/Cargo.toml new file mode 100644 index 00000000..5eb35884 --- /dev/null +++ b/traits/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "solders-traits" +version = "0.9.3" +edition = "2021" +include = ["/src"] +description = "A collection of traits and helpers for Solders." +license = "MIT" +repository = "https://github.com/kevinheavey/solders" + +[dependencies] +pyo3 = { version = "0.17.1", default-features = false } +solana-sdk = "^1.14.1" +bincode = "^1.3.3" +serde = "^1.0.136" +serde_json = "^1.0.59" +serde_cbor = "^0.11.2" diff --git a/traits/src/lib.rs b/traits/src/lib.rs new file mode 100644 index 00000000..a7b81e04 --- /dev/null +++ b/traits/src/lib.rs @@ -0,0 +1,459 @@ +use bincode::ErrorKind; +use pyo3::{ + create_exception, + exceptions::{PyException, PyTypeError, PyValueError}, + prelude::*, + pyclass::CompareOp, + types::PyBytes, +}; +use serde::{Deserialize, Serialize}; +use solana_sdk::{ + commitment_config::ParseCommitmentLevelError as ParseCommitmentLevelErrorOriginal, + hash::ParseHashError as ParseHashErrorOriginal, + pubkey::Pubkey as PubkeyOriginal, + pubkey::PubkeyError as PubkeyErrorOriginal, + sanitize::SanitizeError as SanitizeErrorOriginal, + signature::Signature as SignatureOriginal, + signer::{Signer as SignerTrait, SignerError as SignerErrorOriginal}, + transaction::TransactionError as TransactionErrorOriginal, +}; +use std::{ + collections::hash_map::DefaultHasher, + fmt, + hash::{Hash, Hasher}, +}; + +pub struct PyErrWrapper(pub PyErr); + +impl From for PyErr { + fn from(e: PyErrWrapper) -> Self { + e.0 + } +} + +create_exception!( + solders, + ParseCommitmentLevelError, + PyException, + "Raised when an error is encountered converting a string into a ``CommitmentConfig``." +); + +create_exception!( + solders, + SerdeJSONError, + PyException, + "Raised when an error is encountered during JSON (de)serialization." +); + +impl From for PyErrWrapper { + fn from(e: serde_json::Error) -> Self { + Self(SerdeJSONError::new_err(e.to_string())) + } +} + +impl From for PyErrWrapper { + fn from(e: ParseCommitmentLevelErrorOriginal) -> Self { + Self(ParseCommitmentLevelError::new_err(e.to_string())) + } +} + +create_exception!( + solders, + ParseHashError, + PyException, + "Raised when an error is encountered converting a string into a ``Hash``." +); + +impl From for PyErrWrapper { + fn from(e: ParseHashErrorOriginal) -> Self { + Self(ParseHashError::new_err(e.to_string())) + } +} + +create_exception!( + solders, + SignerError, + PyException, + "Raised when an error is encountered during transaction signing." +); + +impl From for PyErrWrapper { + fn from(e: SignerErrorOriginal) -> Self { + Self(SignerError::new_err(e.to_string())) + } +} + +create_exception!( + solders, + TransactionError, + PyException, + "Umbrella error for the ``Transaction`` object." +); + +impl From for PyErrWrapper { + fn from(e: TransactionErrorOriginal) -> Self { + Self(TransactionError::new_err(e.to_string())) + } +} + +create_exception!( + solders, + SanitizeError, + PyException, + "Raised when an error is encountered during transaction sanitization." +); + +impl From for PyErrWrapper { + fn from(e: SanitizeErrorOriginal) -> Self { + Self(SanitizeError::new_err(e.to_string())) + } +} + +pub fn to_py_err>(e: T) -> PyErr { + let wrapped: PyErrWrapper = e.into(); + wrapped.into() +} + +pub fn handle_py_err, E: ToString + Into, P>( + res: Result, +) -> PyResult

{ + res.map_or_else(|e| Err(to_py_err(e)), |v| Ok(v.into())) +} + +pub fn to_py_value_err(err: &impl ToString) -> PyErr { + PyValueError::new_err(err.to_string()) +} + +pub fn handle_py_value_err, E: ToString, P>(res: Result) -> PyResult

{ + res.map_or_else(|e| Err(to_py_value_err(&e)), |v| Ok(v.into())) +} + +create_exception!( + solders, + BincodeError, + PyException, + "Raised when the Rust bincode library returns an error during (de)serialization." +); + +create_exception!( + solders, + CborError, + PyException, + "Raised when the Rust cbor library returns an error during (de)serialization." +); + +create_exception!( + solders, + PubkeyError, + PyException, + "Umbrella error for the ``Pubkey`` object." +); + +impl From for PyErrWrapper { + fn from(e: PubkeyErrorOriginal) -> Self { + Self(PubkeyError::new_err(e.to_string())) + } +} + +impl From> for PyErrWrapper { + fn from(e: Box) -> Self { + Self(BincodeError::new_err(e.to_string())) + } +} + +impl From for PyErrWrapper { + fn from(e: serde_cbor::Error) -> Self { + Self(CborError::new_err(e.to_string())) + } +} + +fn richcmp_type_error(op: &str) -> PyErr { + let msg = format!("{op} not supported."); + PyTypeError::new_err(msg) +} + +fn calculate_hash(t: &T) -> u64 +where + T: Hash + ?Sized, +{ + let mut s = DefaultHasher::new(); + t.hash(&mut s); + s.finish() +} + +pub trait ToSignerOriginal { + fn to_inner(&self) -> Box; +} + +pub trait SignerTraitWrapper: ToSignerOriginal { + fn pubkey(&self) -> PubkeyOriginal { + self.to_inner().pubkey() + } + fn try_pubkey(&self) -> Result { + self.to_inner().try_pubkey() + } + fn sign_message(&self, message: &[u8]) -> SignatureOriginal { + self.to_inner().sign_message(message) + } + fn try_sign_message(&self, message: &[u8]) -> Result { + self.to_inner().try_sign_message(message) + } + fn is_interactive(&self) -> bool { + self.to_inner().is_interactive() + } +} + +pub trait RichcmpEqualityOnly: PartialEq { + fn richcmp(&self, other: &Self, op: CompareOp) -> PyResult { + match op { + CompareOp::Eq => Ok(self == other), + CompareOp::Ne => Ok(self != other), + CompareOp::Lt => Err(richcmp_type_error("<")), + CompareOp::Gt => Err(richcmp_type_error(">")), + CompareOp::Le => Err(richcmp_type_error("<=")), + CompareOp::Ge => Err(richcmp_type_error(">=")), + } + } +} + +pub trait RichcmpSigner: SignerTraitWrapper { + fn richcmp(&self, other: impl SignerTraitWrapper, op: CompareOp) -> PyResult { + let eq_val = self.pubkey() == other.pubkey(); + match op { + CompareOp::Eq => Ok(eq_val), + CompareOp::Ne => Ok(!eq_val), + CompareOp::Lt => Err(richcmp_type_error("<")), + CompareOp::Gt => Err(richcmp_type_error(">")), + CompareOp::Le => Err(richcmp_type_error("<=")), + CompareOp::Ge => Err(richcmp_type_error(">=")), + } + } +} + +pub trait RichcmpFull: PartialEq + PartialOrd { + fn richcmp(&self, other: &Self, op: CompareOp) -> bool { + match op { + CompareOp::Eq => self == other, + CompareOp::Ne => self != other, + CompareOp::Lt => self < other, + CompareOp::Gt => self > other, + CompareOp::Le => self <= other, + CompareOp::Ge => self >= other, + } + } +} + +#[macro_export] +macro_rules! impl_display { + ($ident:ident) => { + impl std::fmt::Display for $ident { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + }; +} + +#[macro_export] +macro_rules! impl_signer_hash { + ($ident:ident) => { + #[allow(clippy::derive_hash_xor_eq)] + impl std::hash::Hash for $ident { + fn hash(&self, state: &mut H) { + self.pubkey().hash(state); + } + } + }; +} + +pub trait PyHash: Hash { + fn pyhash(&self) -> u64 { + calculate_hash(self) + } +} + +pub trait PyBytesSlice: AsRef<[u8]> { + fn pybytes_slice<'a>(&self, py: Python<'a>) -> &'a PyBytes { + PyBytes::new(py, self.as_ref()) + } +} + +#[macro_export] +macro_rules! pybytes_general_for_pybytes_slice { + ($ident:ident) => { + impl $crate::PyBytesGeneral for $ident { + fn pybytes_general<'a>( + &self, + py: pyo3::prelude::Python<'a>, + ) -> &'a pyo3::types::PyBytes { + self.pybytes_slice(py) + } + } + }; +} + +#[macro_export] +macro_rules! pybytes_general_for_pybytes_bincode { + ($ident:ident) => { + impl $crate::PyBytesGeneral for $ident { + fn pybytes_general<'a>( + &self, + py: pyo3::prelude::Python<'a>, + ) -> &'a pyo3::types::PyBytes { + self.pybytes_bincode(py) + } + } + }; +} + +#[macro_export] +macro_rules! pybytes_general_for_pybytes_cbor { + ($ident:ident) => { + impl $crate::PyBytesGeneral for $ident { + fn pybytes_general<'a>( + &self, + py: pyo3::prelude::Python<'a>, + ) -> &'a pyo3::types::PyBytes { + self.pybytes_cbor(py) + } + } + }; +} + +pub trait PyBytesBincode: Serialize { + fn pybytes_bincode<'a>(&self, py: Python<'a>) -> &'a PyBytes { + PyBytes::new(py, &bincode::serialize(self).unwrap()) + } +} + +pub trait PyBytesCbor: Serialize + std::marker::Sized { + fn pybytes_cbor<'a>(&self, py: Python<'a>) -> &'a PyBytes { + PyBytes::new(py, &serde_cbor::to_vec(self).unwrap()) + } +} + +pub trait PyBytesGeneral { + fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes; +} + +#[macro_export] +macro_rules! pybytes_general_via_slice { + ($ident:ident) => { + impl $crate::PyBytesSlice for $ident {} + $crate::pybytes_general_for_pybytes_slice!($ident); + }; +} + +#[macro_export] +macro_rules! pybytes_general_via_bincode { + ($ident:ident) => { + impl $crate::PyBytesBincode for $ident {} + $crate::pybytes_general_for_pybytes_bincode!($ident); + }; +} + +#[macro_export] +macro_rules! pybytes_general_via_cbor { + ($ident:ident) => { + impl $crate::PyBytesCbor for $ident {} + $crate::pybytes_general_for_pybytes_cbor!($ident); + }; +} + +#[macro_export] +macro_rules! py_from_bytes_general_for_py_from_bytes_bincode { + ($ident:ident) => { + impl $crate::PyFromBytesGeneral for $ident { + fn py_from_bytes_general(raw: &[u8]) -> PyResult { + Self::py_from_bytes_bincode(raw) + } + } + }; +} + +#[macro_export] +macro_rules! py_from_bytes_general_for_py_from_bytes_cbor { + ($ident:ident) => { + impl $crate::PyFromBytesGeneral for $ident { + fn py_from_bytes_general(raw: &[u8]) -> PyResult { + Self::py_from_bytes_cbor(raw) + } + } + }; +} + +#[macro_export] +macro_rules! py_from_bytes_general_via_bincode { + ($ident:ident) => { + impl $crate::PyFromBytesBincode<'_> for $ident {} + $crate::py_from_bytes_general_for_py_from_bytes_bincode!($ident); + }; +} + +pub trait PyFromBytesBincode<'b>: Deserialize<'b> { + fn py_from_bytes_bincode(raw: &'b [u8]) -> PyResult { + let deser = bincode::deserialize::(raw); + handle_py_err(deser) + } +} + +#[macro_export] +macro_rules! py_from_bytes_general_via_cbor { + ($ident:ident) => { + impl $crate::PyFromBytesCbor<'_> for $ident {} + $crate::py_from_bytes_general_for_py_from_bytes_cbor!($ident); + }; +} + +pub trait PyFromBytesCbor<'b>: Deserialize<'b> { + fn py_from_bytes_cbor(raw: &'b [u8]) -> PyResult { + let deser = serde_cbor::from_slice::(raw); + handle_py_err(deser) + } +} + +pub trait PyFromBytesGeneral: Sized { + fn py_from_bytes_general(raw: &[u8]) -> PyResult; +} + +pub trait CommonMethods<'a>: + fmt::Display + + fmt::Debug + + PyBytesGeneral + + PyFromBytesGeneral + + IntoPy + + Clone + + Serialize + + Deserialize<'a> +{ + fn pybytes<'b>(&self, py: Python<'b>) -> &'b PyBytes { + self.pybytes_general(py) + } + + fn pystr(&self) -> String { + self.to_string() + } + fn pyrepr(&self) -> String { + format!("{self:#?}") + } + + fn py_from_bytes(raw: &[u8]) -> PyResult { + Self::py_from_bytes_general(raw) + } + + fn pyreduce(&self) -> PyResult<(PyObject, PyObject)> { + let cloned = self.clone(); + Python::with_gil(|py| { + let constructor = cloned.into_py(py).getattr(py, "from_bytes")?; + Ok((constructor, (self.pybytes(py).to_object(py),).to_object(py))) + }) + } + + fn py_to_json(&self) -> String { + serde_json::to_string(self).unwrap() + } + + fn py_from_json(raw: &'a str) -> PyResult { + serde_json::from_str(raw).map_err(to_py_err) + } +}