diff --git a/packages/backend/bindings/node/index.ts b/packages/backend/bindings/node/index.ts index 28cb05d1d92..5340578723e 100644 --- a/packages/backend/bindings/node/index.ts +++ b/packages/backend/bindings/node/index.ts @@ -76,6 +76,9 @@ export function init(id: string, storagePath?: string) { destroy() { destroyed = true runtime.destroy() + }, + removeEventListeners() { + runtime.removeEventListeners() } } } diff --git a/packages/backend/bindings/node/native/Cargo.lock b/packages/backend/bindings/node/native/Cargo.lock index f8f70f8795b..7dd34b1c503 100644 --- a/packages/backend/bindings/node/native/Cargo.lock +++ b/packages/backend/bindings/node/native/Cargo.lock @@ -84,6 +84,17 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +[[package]] +name = "ahash" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" +dependencies = [ + "getrandom 0.2.2", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.15" @@ -268,7 +279,7 @@ dependencies = [ [[package]] name = "bee-common" version = "0.3.1-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=dev#48b73fdc08356c7e5d53d9503dc963409f537fd2" +source = "git+https://github.com/iotaledger/bee.git?branch=dev#a65bfad5dfdc8aa46d34b6b58899007a43d72340" dependencies = [ "autocfg", "chrono", @@ -283,7 +294,7 @@ name = "bee-crypto" version = "0.2.0-alpha" source = "git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4#c42171ff33c80cc2efb183e244dc79b7f58d9ac4" dependencies = [ - "bee-ternary 0.4.0-alpha (git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4)", + "bee-ternary 0.4.0-alpha", "byteorder", "lazy_static", "thiserror", @@ -293,9 +304,9 @@ dependencies = [ [[package]] name = "bee-crypto" version = "0.2.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=dev#48b73fdc08356c7e5d53d9503dc963409f537fd2" +source = "git+https://github.com/iotaledger/bee.git?branch=dev#a65bfad5dfdc8aa46d34b6b58899007a43d72340" dependencies = [ - "bee-ternary 0.4.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-ternary 0.4.1-alpha", "byteorder", "lazy_static", "thiserror", @@ -305,17 +316,27 @@ dependencies = [ [[package]] name = "bee-ledger" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" +dependencies = [ + "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "thiserror", +] + +[[package]] +name = "bee-ledger" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-message", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "bee-runtime", "bee-snapshot", "bee-storage", "bee-tangle", - "bee-ternary 0.4.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-ternary 0.4.1-alpha", "digest 0.9.0", "flume", "futures", @@ -331,11 +352,27 @@ dependencies = [ [[package]] name = "bee-message" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" +dependencies = [ + "bech32", + "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "digest 0.9.0", + "hex", + "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=c3bf565eba62d0b81144174c2ff917bfde282e49)", + "ref-cast", + "serde 1.0.124", + "thiserror", +] + +[[package]] +name = "bee-message" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "bech32", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-pow", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "digest 0.9.0", "hex", "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=c3bf565eba62d0b81144174c2ff917bfde282e49)", @@ -347,7 +384,26 @@ dependencies = [ [[package]] name = "bee-network" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" +dependencies = [ + "async-trait", + "bee-runtime", + "futures", + "lazy_static", + "libp2p", + "log", + "rand 0.8.3", + "serde 1.0.124", + "thiserror", + "tokio", + "tokio-stream", + "url", +] + +[[package]] +name = "bee-network" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "async-trait", "bee-runtime", @@ -366,32 +422,52 @@ dependencies = [ [[package]] name = "bee-pow" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" dependencies = [ "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-ternary 0.4.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-ternary 0.4.1-alpha", "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=c3bf565eba62d0b81144174c2ff917bfde282e49)", "thiserror", ] +[[package]] +name = "bee-pow" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" +dependencies = [ + "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-ternary 0.4.1-alpha", + "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=c3bf565eba62d0b81144174c2ff917bfde282e49)", + "thiserror", +] + +[[package]] +name = "bee-protocol" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" +dependencies = [ + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-network 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", +] + [[package]] name = "bee-protocol" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "async-channel", "async-priority-queue", "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-ledger", - "bee-message", - "bee-network", + "bee-ledger 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-network 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "bee-runtime", "bee-snapshot", "bee-storage", "bee-tangle", - "bee-ternary 0.4.0-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", + "bee-ternary 0.4.1-alpha", "futures", "futures-util", "fxhash", @@ -413,35 +489,36 @@ dependencies = [ [[package]] name = "bee-rest-api" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482#217b5944b5e17fe5800955d212cfe8dddd992482" dependencies = [ - "async-trait", - "bech32", - "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-ledger", - "bee-message", - "bee-network", - "bee-pow", - "bee-protocol", + "bee-ledger 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-protocol 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "hex", + "serde 1.0.124", + "serde_json", +] + +[[package]] +name = "bee-rest-api" +version = "0.1.0-alpha" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" +dependencies = [ + "bee-ledger 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-protocol 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "bee-runtime", - "bee-storage", - "bee-tangle", - "digest 0.9.0", - "futures", "hex", - "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=c3bf565eba62d0b81144174c2ff917bfde282e49)", - "log", - "num_cpus", "serde 1.0.124", "serde_json", - "tokio", - "warp", ] [[package]] name = "bee-runtime" version = "0.1.1-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=dev#48b73fdc08356c7e5d53d9503dc963409f537fd2" +source = "git+https://github.com/iotaledger/bee.git?branch=dev#a65bfad5dfdc8aa46d34b6b58899007a43d72340" dependencies = [ "async-trait", "bee-storage", @@ -453,11 +530,11 @@ dependencies = [ [[package]] name = "bee-snapshot" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-message", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "bee-runtime", "bee-storage", "chrono", @@ -473,7 +550,7 @@ dependencies = [ [[package]] name = "bee-storage" version = "0.2.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=dev#48b73fdc08356c7e5d53d9503dc963409f537fd2" +source = "git+https://github.com/iotaledger/bee.git?branch=dev#a65bfad5dfdc8aa46d34b6b58899007a43d72340" dependencies = [ "async-trait", "futures", @@ -483,18 +560,18 @@ dependencies = [ [[package]] name = "bee-tangle" version = "0.1.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?rev=d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4#d379dc3f6d96bca53c32e53feb3e6b7a0a7372b4" +source = "git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05#26215e3af88af4c54f460df7cffc39d26fdd6e05" dependencies = [ "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", - "bee-message", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "bee-runtime", "bee-snapshot", "bee-storage", "bitflags", "dashmap 4.0.2", "futures", - "hashbrown", + "hashbrown 0.11.0", "log", "lru", "rand 0.8.3", @@ -515,8 +592,8 @@ dependencies = [ [[package]] name = "bee-ternary" -version = "0.4.0-alpha" -source = "git+https://github.com/iotaledger/bee.git?branch=dev#48b73fdc08356c7e5d53d9503dc963409f537fd2" +version = "0.4.1-alpha" +source = "git+https://github.com/iotaledger/bee.git?branch=dev#a65bfad5dfdc8aa46d34b6b58899007a43d72340" dependencies = [ "autocfg", "num-traits 0.2.14", @@ -594,16 +671,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" -[[package]] -name = "buf_redux" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" -dependencies = [ - "memchr", - "safemem", -] - [[package]] name = "bumpalo" version = "3.6.1" @@ -1311,37 +1378,21 @@ dependencies = [ ] [[package]] -name = "hashlink" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8" -dependencies = [ - "hashbrown", -] - -[[package]] -name = "headers" -version = "0.3.4" +name = "hashbrown" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" +checksum = "362385356d610bd1e5a408ddf8d022041774b683f345a1d2cfcb4f60f8ae2db5" dependencies = [ - "base64", - "bitflags", - "bytes", - "headers-core", - "http", - "mime", - "sha-1", - "time", + "ahash 0.7.2", ] [[package]] -name = "headers-core" -version = "0.2.0" +name = "hashlink" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +checksum = "d99cf782f0dc4372d26846bec3de7804ceb5df083c2d4462c0b8d2330e894fa8" dependencies = [ - "http", + "hashbrown 0.9.1", ] [[package]] @@ -1422,12 +1473,13 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" +checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" dependencies = [ "bytes", "http", + "pin-project-lite", ] [[package]] @@ -1549,16 +1601,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", - "hashbrown", -] - -[[package]] -name = "input_buffer" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" -dependencies = [ - "bytes", + "hashbrown 0.9.1", ] [[package]] @@ -1573,18 +1616,19 @@ dependencies = [ [[package]] name = "iota-client" version = "0.5.0-alpha.3" -source = "git+https://github.com/iotaledger/iota.rs?rev=1554893c01d37ef067a4d7559e33a0da48401cac#1554893c01d37ef067a4d7559e33a0da48401cac" +source = "git+https://github.com/iotaledger/iota.rs?rev=f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0#f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0" dependencies = [ "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4)", - "bee-message", - "bee-pow", - "bee-rest-api", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-rest-api 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", "chrono", "futures", "hex", "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=b849861b86c3f7357b7477de4253b7352b363627)", + "log", "num_cpus", "once_cell", "regex", @@ -1600,17 +1644,18 @@ dependencies = [ [[package]] name = "iota-client" version = "0.5.0-alpha.3" -source = "git+https://github.com/iotaledger/iota.rs?branch=dev#57a9e6809e2b67a7bd2787ea9b0be5b45fc63385" +source = "git+https://github.com/iotaledger/iota.rs?branch=dev#23b8faf6ba7cce4a58fb47bb302bd56c4430758c" dependencies = [ "async-trait", "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?branch=dev)", "bee-crypto 0.2.0-alpha (git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4)", - "bee-message", - "bee-pow", - "bee-rest-api", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-rest-api 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", "chrono", "hex", "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=b849861b86c3f7357b7477de4253b7352b363627)", + "log", "num_cpus", "reqwest", "serde 1.0.124", @@ -1623,22 +1668,22 @@ dependencies = [ [[package]] name = "iota-core" version = "0.2.0-alpha.3" -source = "git+https://github.com/iotaledger/iota.rs?rev=1554893c01d37ef067a4d7559e33a0da48401cac#1554893c01d37ef067a4d7559e33a0da48401cac" +source = "git+https://github.com/iotaledger/iota.rs?rev=f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0#f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0" dependencies = [ "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4)", - "bee-message", - "bee-pow", - "iota-client 0.5.0-alpha.3 (git+https://github.com/iotaledger/iota.rs?rev=1554893c01d37ef067a4d7559e33a0da48401cac)", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=26215e3af88af4c54f460df7cffc39d26fdd6e05)", + "iota-client 0.5.0-alpha.3 (git+https://github.com/iotaledger/iota.rs?rev=f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0)", ] [[package]] name = "iota-core" version = "0.2.0-alpha.3" -source = "git+https://github.com/iotaledger/iota.rs?branch=dev#57a9e6809e2b67a7bd2787ea9b0be5b45fc63385" +source = "git+https://github.com/iotaledger/iota.rs?branch=dev#23b8faf6ba7cce4a58fb47bb302bd56c4430758c" dependencies = [ "bee-common 0.3.1-alpha (git+https://github.com/iotaledger/bee.git?rev=c42171ff33c80cc2efb183e244dc79b7f58d9ac4)", - "bee-message", - "bee-pow", + "bee-message 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", + "bee-pow 0.1.0-alpha (git+https://github.com/iotaledger/bee.git?rev=217b5944b5e17fe5800955d212cfe8dddd992482)", "iota-client 0.5.0-alpha.3 (git+https://github.com/iotaledger/iota.rs?branch=dev)", ] @@ -1697,7 +1742,7 @@ dependencies = [ [[package]] name = "iota-wallet" version = "0.1.0" -source = "git+https://github.com/iotaledger/wallet.rs?branch=develop#292fbdca4cfca5f6b663911774d4ce3ec5a74a9e" +source = "git+https://github.com/iotaledger/wallet.rs?branch=develop#c867c2c8a194ed8897a28980030b96473e8b23c9" dependencies = [ "async-trait", "backtrace", @@ -1706,7 +1751,7 @@ dependencies = [ "futures", "getset", "hex", - "iota-core 0.2.0-alpha.3 (git+https://github.com/iotaledger/iota.rs?rev=1554893c01d37ef067a4d7559e33a0da48401cac)", + "iota-core 0.2.0-alpha.3 (git+https://github.com/iotaledger/iota.rs?rev=f837a9df7c0f3cecbff87eb6ac3d458d1e50dee0)", "iota-crypto 0.3.0 (git+https://github.com/iotaledger/crypto.rs?rev=b849861b86c3f7357b7477de4253b7352b363627)", "iota-stronghold", "log", @@ -1748,9 +1793,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.48" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" +checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821" dependencies = [ "wasm-bindgen", ] @@ -1776,9 +1821,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.88" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" +checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae" [[package]] name = "libp2p" @@ -2044,7 +2089,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f374d42cdfc1d7dbf3d3dec28afab2eb97ffbf43a3234d795b5986dbf4b90ba" dependencies = [ - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -2065,16 +2110,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "miniz_oxide" version = "0.4.4" @@ -2087,9 +2122,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" +checksum = "2182a122f3b7f3f5329cb1972cee089ba2459a0a80a56935e6e674f096f8d839" dependencies = [ "libc", "log", @@ -2146,27 +2181,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" - -[[package]] -name = "multipart" -version = "0.17.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" -dependencies = [ - "buf_redux", - "httparse", - "log", - "mime", - "mime_guess", - "quick-error", - "rand 0.7.3", - "safemem", - "tempfile", - "twoway", -] +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" @@ -2401,9 +2418,9 @@ dependencies = [ [[package]] name = "parity-multiaddr" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c6805f98667a3828afb2ec2c396a8d610497e8d546f5447188aae47c5a79ec" +checksum = "58341485071825827b7f03cf7efd1cb21e6a709bea778fb50227fd45d2f361b4" dependencies = [ "arrayref", "bs58", @@ -2456,9 +2473,9 @@ checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "pbkdf2" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309c95c5f738c85920eb7062a2de29f3840d4f96974453fc9ac1ba078da9c627" +checksum = "297e1dad0e9de7af53235b833761351bf6bda57d6acb4f263b61a2ddf674f1dc" dependencies = [ "crypto-mac 0.10.0", ] @@ -2552,9 +2569,9 @@ dependencies = [ [[package]] name = "pollster" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0c427c464eaca5923b642b3b346792b9c98edd91026aa6a753435e42d2a07b" +checksum = "75721b4c756dd61e006f1d3fe1e44bda75ad3a3d8eaa45e9f32943cbe635e663" [[package]] name = "poly1305" @@ -2706,12 +2723,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "0.6.13" @@ -3055,12 +3066,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "safemem" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" - [[package]] name = "schannel" version = "0.1.19" @@ -3071,12 +3076,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "scopeguard" version = "1.1.0" @@ -3213,19 +3212,6 @@ dependencies = [ "serde 1.0.124", ] -[[package]] -name = "sha-1" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpuid-bool 0.1.2", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - [[package]] name = "sha2" version = "0.8.2" @@ -3602,19 +3588,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-tungstenite" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b" -dependencies = [ - "futures-util", - "log", - "pin-project 1.0.5", - "tokio", - "tungstenite", -] - [[package]] name = "tokio-util" version = "0.6.4" @@ -3651,7 +3624,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", - "log", "pin-project-lite", "tracing-core", ] @@ -3665,50 +3637,12 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project 1.0.5", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "tungstenite" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24" -dependencies = [ - "base64", - "byteorder", - "bytes", - "http", - "httparse", - "input_buffer", - "log", - "rand 0.8.3", - "sha-1", - "url", - "utf-8", -] - -[[package]] -name = "twoway" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" -dependencies = [ - "memchr", -] - [[package]] name = "twox-hash" version = "1.6.0" @@ -3726,15 +3660,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -3831,12 +3756,6 @@ dependencies = [ "serde 1.0.124", ] -[[package]] -name = "utf-8" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" - [[package]] name = "uuid" version = "0.8.2" @@ -3872,9 +3791,9 @@ checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "void" @@ -3912,36 +3831,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "warp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dafd0aac2818a94a34df0df1100a7356c493d8ede4393875fd0b5c51bb6bc80" -dependencies = [ - "bytes", - "futures", - "headers", - "http", - "hyper", - "log", - "mime", - "mime_guess", - "multipart", - "percent-encoding", - "pin-project 1.0.5", - "scoped-tls", - "serde 1.0.124", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-stream", - "tokio-tungstenite", - "tokio-util", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -3956,9 +3845,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.71" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" +checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe" dependencies = [ "cfg-if 1.0.0", "serde 1.0.124", @@ -3968,9 +3857,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.71" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" +checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" dependencies = [ "bumpalo", "lazy_static", @@ -3983,9 +3872,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" +checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3995,9 +3884,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.71" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" +checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b" dependencies = [ "quote 1.0.9", "wasm-bindgen-macro-support", @@ -4005,9 +3894,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.71" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" +checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", @@ -4018,9 +3907,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.71" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" +checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa" [[package]] name = "wasm-timer" @@ -4039,9 +3928,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.48" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" +checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/packages/backend/bindings/node/native/src/lib.rs b/packages/backend/bindings/node/native/src/lib.rs index 7ed012b01cf..0d2ad48fd5c 100644 --- a/packages/backend/bindings/node/native/src/lib.rs +++ b/packages/backend/bindings/node/native/src/lib.rs @@ -7,7 +7,7 @@ use std::sync::{ }; use tokio::runtime::Runtime; use wallet_actor_system::{ - destroy as destroy_actor, init as init_actor, init_logger as init_backend_logger, + destroy as destroy_actor, remove_event_listeners as remove_actor_event_listeners, init as init_actor, init_logger as init_backend_logger, listen as add_event_listener, send_message as send_actor_message, EventType, LoggerConfigBuilder, }; @@ -105,6 +105,13 @@ declare_types! { Ok(cx.undefined().upcast()) } + method removeEventListeners(mut cx) { + let this = cx.this(); + let actor_id = cx.borrow(&this, |emitter| emitter.actor_id.clone()); + block_on(remove_actor_event_listeners(actor_id)); + Ok(cx.undefined().upcast()) + } + // This method should be called by JS to receive data. It accepts a // `function (err, data)` style asynchronous callback. It may be called // in a loop, but care should be taken to only call it once at a time. diff --git a/packages/backend/src/lib.rs b/packages/backend/src/lib.rs index 9ba271ffda0..07a724c3efa 100644 --- a/packages/backend/src/lib.rs +++ b/packages/backend/src/lib.rs @@ -98,6 +98,7 @@ pub async fn init, F: Fn(String) + Send + Sync + 'static>( ) .unwrap() //safe to unwrap, the storage password is None ^ .with_polling_interval(Duration::from_millis(POLLING_INTERVAL_MS)) + .with_sync_spent_outputs() .finish() .await .expect("failed to init account manager"); @@ -123,12 +124,16 @@ pub async fn init, F: Fn(String) + Send + Sync + 'static>( .await; } -pub async fn destroy>(actor_id: A) { +pub async fn remove_event_listeners>(actor_id: A) { let mut actors = wallet_actors().lock().await; - let actor_id = actor_id.into(); + if let Some(actor_data) = actors.get_mut(&actor_id.into()) { + remove_event_listeners_internal(&actor_data.listeners).await; + actor_data.listeners = Vec::new(); + } +} - if let Some(actor_data) = actors.remove(&actor_id) { - for (event_id, event_type) in &actor_data.listeners { +async fn remove_event_listeners_internal(listeners: &[(EventId, EventType)]) { + for (event_id, event_type) in listeners.iter() { match event_type { &EventType::ErrorThrown => remove_error_listener(event_id), &EventType::BalanceChange => remove_balance_change_listener(event_id).await, @@ -144,6 +149,14 @@ pub async fn destroy>(actor_id: A) { &EventType::TransferProgress => remove_transfer_progress_listener(event_id).await, }; } +} + +pub async fn destroy>(actor_id: A) { + let mut actors = wallet_actors().lock().await; + let actor_id = actor_id.into(); + + if let Some(actor_data) = actors.remove(&actor_id) { + remove_event_listeners_internal(&actor_data.listeners).await; actor_data.actor.tell(actors::KillMessage, None); iota_wallet::with_actor_system(|sys| { diff --git a/packages/shared/lib/typings/bridge.ts b/packages/shared/lib/typings/bridge.ts index b8bb3b33186..69041ac09d3 100644 --- a/packages/shared/lib/typings/bridge.ts +++ b/packages/shared/lib/typings/bridge.ts @@ -6,6 +6,7 @@ import type { StrongholdStatus } from './wallet' export interface Actor { destroy(): void + removeEventListeners(): void } export interface CommunicationIds { diff --git a/packages/shared/lib/typings/events.ts b/packages/shared/lib/typings/events.ts index 667de44df03..7ca703fed8c 100644 --- a/packages/shared/lib/typings/events.ts +++ b/packages/shared/lib/typings/events.ts @@ -82,6 +82,7 @@ export interface ErrorEventPayload { } export interface BalanceChangeEventPayload { + indexationId: string accountId: string address: Address balanceChange: { @@ -101,6 +102,13 @@ export interface ConfirmationStateChangeEventPayload { confirmed: boolean } +export interface ReattachmentEventPayload { + indexationId: string; + accountId: string; + message: Message; + reattachedMessageId: string; +} + export enum TransferProgressEventType { // Syncing account. SyncingAccount = 'SyncingAccount', diff --git a/packages/shared/lib/wallet.ts b/packages/shared/lib/wallet.ts index 8e0dccbdd6b..54645d1fd55 100644 --- a/packages/shared/lib/wallet.ts +++ b/packages/shared/lib/wallet.ts @@ -134,6 +134,19 @@ export const initialise = (id: string, storagePath: string): void => { actors[id] = actor } +/** + * Removes event listeners for active actor + * + * @method removeEventListeners + * + * @param {string} id + * + * @returns {void} + */ +export const removeEventListeners = (id: string): void => { + actors[id].removeEventListeners() +}; + /** * Destroys an actor & remove it from actors state * @@ -306,20 +319,41 @@ export const initialiseListeners = () => { const account = get(accounts).find((account) => account.id === response.payload.accountId) const message = response.payload.message + const essence = message.payload.data.essence + + if (!get(isSyncing)) { + if (!essence.data.internal) { + const { balanceOverview } = get(wallet); + const overview = get(balanceOverview); + + const incoming = essence.data.incoming ? overview.incomingRaw + essence.data.value : overview.incomingRaw; + const outgoing = essence.data.incoming ? overview.outgoingRaw : overview.outgoingRaw + essence.data.value; + + updateBalanceOverview( + overview.balanceRaw, + incoming, + outgoing + ); + } + + // Update account with new message + saveNewMessage(response.payload.accountId, response.payload.message); + } + const notificationMessage = localize('notifications.valueTx') .replace('{{value}}', formatUnit(message.payload.data.essence.data.value)) .replace('{{account}}', account.alias) showSystemNotification({ type: "info", message: notificationMessage }) - - // Update account with new message - saveNewMessage(response.payload.accountId, response.payload.message); }, onError(error) { console.error(error) }, }) + /** + * Event listener for transfer confirmation state change + */ api.onConfirmationStateChange({ onSuccess(response) { const accounts = get(wallet).accounts @@ -327,27 +361,45 @@ export const initialiseListeners = () => { const message = response.payload.message const messageKey = response.payload.confirmed ? 'confirmed' : 'failed' - const accountMessage = account.messages.find((_message) => _message.id === message.id) - accountMessage.confirmed = response.payload.confirmed - accounts.update((storedAccounts) => { - return storedAccounts.map((storedAccount) => { - if (storedAccount.id === account.id) { - return Object.assign, Partial>({} as WalletAccount, storedAccount, { - messages: storedAccount.messages.map((_message: Message) => { - if (_message.id === message.id) { - return Object.assign, Partial>( - {} as Message, - _message, - { confirmed: response.payload.confirmed } - ) - } - return _message + const essence = message.payload.data.essence + + if (!get(isSyncing)) { + if (response.payload.confirmed && !essence.data.internal) { + const { balanceOverview } = get(wallet); + const overview = get(balanceOverview); + + const incoming = essence.data.incoming ? overview.incomingRaw + essence.data.value : overview.incomingRaw; + const outgoing = essence.data.incoming ? overview.outgoingRaw : overview.outgoingRaw + essence.data.value; + + updateBalanceOverview( + overview.balanceRaw, + incoming, + outgoing + ); + } + + const accountMessage = account.messages.find((_message) => _message.id === message.id) + accountMessage.confirmed = response.payload.confirmed + accounts.update((storedAccounts) => { + return storedAccounts.map((storedAccount) => { + if (storedAccount.id === account.id) { + return Object.assign, Partial>({} as WalletAccount, storedAccount, { + messages: storedAccount.messages.map((_message: Message) => { + if (_message.id === message.id) { + return Object.assign, Partial>( + {} as Message, + _message, + { confirmed: response.payload.confirmed } + ) + } + return _message + }) }) - }) - } - return storedAccount + } + return storedAccount + }) }) - }) + } const notificationMessage = localize(`notifications.${messageKey}`) .replace('{{value}}', formatUnit(message.payload.data.essence.data.value)) @@ -365,25 +417,40 @@ export const initialiseListeners = () => { */ api.onBalanceChange({ onSuccess(response) { - const { payload: { accountId, address, balanceChange } } = response; - - updateAccountAfterBalanceChange(accountId, address, balanceChange.received, balanceChange.spent) - - const { balanceOverview } = get(wallet); - const overview = get(balanceOverview); - - const incoming = overview.incomingRaw + balanceChange.received; - const outgoing = overview.outgoingRaw + balanceChange.spent; - const balance = overview.balanceRaw - balanceChange.spent + balanceChange.received - - updateBalanceOverview(balance, incoming, outgoing); + if (!get(isSyncing)) { + const { payload: { accountId, address, balanceChange } } = response; + + updateAccountAfterBalanceChange(accountId, address, balanceChange.received, balanceChange.spent) + + const { balanceOverview } = get(wallet); + const overview = get(balanceOverview); + + const balance = overview.balanceRaw - balanceChange.spent + balanceChange.received + + updateBalanceOverview(balance, overview.incomingRaw, overview.outgoingRaw); + } + }, + onError(error) { + console.error(error) + }, + }) + /** + * Event listener for reattachment + */ + api.onReattachment({ + onSuccess(response) { + // Replace original message with reattachment + replaceMessage(response.payload.accountId, response.payload.reattachedMessageId, response.payload.message); }, onError(error) { console.error(error) }, }) + /** + * Event listener for transfer progress + */ api.onTransferProgress({ onSuccess(response) { transferState.set(response.payload.event.type) @@ -464,6 +531,37 @@ export const saveNewMessage = (accountId: string, message: Message): void => { }) }; +/** + * @method replaceMessage + * + * @param {string} accountId + * @param {string} messageId + * @param {Message} newMessage + * + * @returns {void} + */ +export const replaceMessage = (accountId: string, messageId: string, newMessage: Message): void => { + const { accounts } = get(wallet) + + accounts.update((storedAccounts) => { + return storedAccounts.map((storedAccount: WalletAccount) => { + if (storedAccount.id === accountId) { + return Object.assign, Partial>({} as WalletAccount, storedAccount, { + messages: storedAccount.messages.map((_message) => { + if (_message.id === messageId) { + return newMessage; + } + + return _message; + }) + }) + } + + return storedAccount; + }) + }) +}; + /** * Gets latest messages * @@ -487,14 +585,34 @@ export const getLatestMessages = (accounts: WalletAccount[], count = 10): Accoun }) account.messages.forEach((message) => { - messages[message.id] = Object.assign< - AccountMessage, - Message, - Partial - >( - {} as AccountMessage, - message, - { account: account.index }); + + if (message.id in messages) { + const existingMessage = messages[message.id]; + + // If a copy of the message exists, only override it if the new message is confirmed and the existing one is unconfirmed + // Imagine an internal transfer (between accounts). + // If the first account already updates the confirmation state as confirmed, there is a chance that the user might see the confirmation state + // changing from confirmed to unconfirmed. To avoid that, we always give preference to the message that's already confirmed. + if (!existingMessage.confirmed && message.confirmed) { + messages[message.id] = Object.assign< + AccountMessage, + Message, + Partial + >( + {} as AccountMessage, + message, + { account: account.index }); + } + } else { + messages[message.id] = Object.assign< + AccountMessage, + Message, + Partial + >( + {} as AccountMessage, + message, + { account: account.index }); + } }) }); diff --git a/packages/shared/lib/walletApi.ts b/packages/shared/lib/walletApi.ts index d39bd4572de..ea217fc26ca 100644 --- a/packages/shared/lib/walletApi.ts +++ b/packages/shared/lib/walletApi.ts @@ -11,7 +11,15 @@ import type { } from './typings/bridge' import { ResponseTypes } from './typings/bridge' import type { ClientOptions } from './typings/client' -import type { BalanceChangeEventPayload, ConfirmationStateChangeEventPayload, ErrorEventPayload, Event, TransactionEventPayload, TransferProgressEventPayload } from './typings/events' +import type { + BalanceChangeEventPayload, + ConfirmationStateChangeEventPayload, + ErrorEventPayload, + Event, + TransactionEventPayload, + TransferProgressEventPayload, + ReattachmentEventPayload +} from './typings/events' import { ErrorType } from './typings/events' import type { Message } from './typings/message' import type { StrongholdStatus, Duration } from './typings/wallet' @@ -123,18 +131,20 @@ const eventsApiResponseTypes = Object.values(eventsApiToResponseTypeMap) */ Wallet.onMessage((message: MessageResponse) => { + console.log(message) + if (message && message.id === undefined) { // There is no message id // Something lower level has thrown an error // We should stop processing at this point const newError = { type: ErrorType.ClientError, message: JSON.stringify(message), time: Date.now() }; - errorLog.update((log) => [ newError, ...log ]) + errorLog.update((log) => [newError, ...log]) console.error(newError) return } const _deleteCallbackId = (_id: string) => { - // Do not delete callback ids for events api methods + // Do not delete callback ids for events api methods if (!eventsApiResponseTypes.includes(message.type)) { delete callbacksStore[_id] } @@ -325,6 +335,7 @@ export interface ApiClient { onStrongholdStatusChange(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) onNewTransaction(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) + onReattachment(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) onConfirmationStateChange(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) onBalanceChange(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) onTransferProgress(callbacks: { onSuccess: (response: Event) => void, onError: (err: ErrorEventPayload) => void }) diff --git a/packages/shared/routes/dashboard/wallet/Wallet.svelte b/packages/shared/routes/dashboard/wallet/Wallet.svelte index bf61fe00846..f0f6695f226 100644 --- a/packages/shared/routes/dashboard/wallet/Wallet.svelte +++ b/packages/shared/routes/dashboard/wallet/Wallet.svelte @@ -7,7 +7,7 @@ import { DEFAULT_NODE, DEFAULT_NODES, network } from 'shared/lib/network' import { showAppNotification } from 'shared/lib/notifications' import { openPopup } from 'shared/lib/popup' - import { isStrongholdLocked } from 'shared/lib/profile' + import { activeProfile, isStrongholdLocked } from 'shared/lib/profile' import { walletRoute } from 'shared/lib/router' import { WalletRoutes } from 'shared/lib/typings/routes' import { @@ -28,6 +28,7 @@ updateBalanceOverview, wallet, WalletAccount, + removeEventListeners } from 'shared/lib/wallet' import { onMount, setContext } from 'svelte' import { derived, Readable, Writable } from 'svelte/store' @@ -356,6 +357,8 @@ getAccounts() } + removeEventListeners($activeProfile.id) + initialiseListeners() api.getStrongholdStatus({