Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base implementation for PSKB and usage in core account with generator wrapper #64

Merged
merged 12 commits into from
Jul 20, 2024

Conversation

1bananagirl
Copy link

No description provided.

let outputs: Vec<Output> = transaction
.outputs
.iter()
.filter_map(|output| Output::try_from(TransactionOutput::from(output.to_owned())).ok())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about explicitly returning error if conversion is failed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

.outputs
.iter()
.filter_map(|output| Output::try_from(TransactionOutput::from(output.to_owned())).ok())
.collect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about explicitly returning error if conversion is failed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

async fn pskb_from_send_generator(
self: Arc<Self>,
destination: PaymentDestination,
priority_fee_sompi: Fees,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering how priority fee will be distibuten between txs? is it accumulative or per tx fee?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per tx fee.
I've added a verifier function to loop through UTXOs and check if fee is coverable for each one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add doc comment describing it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added and function named changed to an explicit one.

return Some(Ok(SignInputOk {
signature: Signature::Schnorr(signature),
pub_key: public_key,
key_source: None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to pass derivation path and fingerprint here?

signature: Signature::Schnorr(signer.sign_schnorr(address, msg).unwrap()),
pub_key: public_key,
key_source: None,
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to pass derivation path and fingerprint here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines 246 to 257
iter::once(OpData65).chain(signature.into_bytes()).chain([input.sighash_type.to_u8()])
})
.collect();

signatures
.into_iter()
.chain(
input
.redeem_script
.as_ref()
.map(|redeem_script| ScriptBuilder::new().add_data(redeem_script.as_slice()).unwrap().drain().to_vec())
.unwrap_or_default(),
Copy link
Collaborator

@biryukovmaxim biryukovmaxim Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct in case of multisig: [signatures]+redeem_script.
in general it depends on script.
for example in case of krc20 it will be one signature + redeem_script.
in case of script OpcodeTrue it will be empty signatures + OpCodeTrue.

this function must have name/generic explaining when it's useful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to finalize_pskt_one_or_more_sig_and_redeem_script, also works for krc20.

New function added: finalize_pskt_no_sig_and_redeem_script

wallet/pskt/src/bundle.rs Outdated Show resolved Hide resolved
Ok(signed_bundle)
}

pub fn bundle_to_finalizer_stream(bundle: &Bundle) -> Pin<Box<dyn Stream<Item = Result<PSKT<Finalizer>, Error>> + Send>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible to return impl Stream, without boxing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -146,13 +146,15 @@ pub fn script_addr(script_sig: &[u8], prefix: kaspa_addresses::Prefix) -> Result
extract_script_pub_key_address(&pay_to_script_hash_script(script_sig), prefix).map_err(Error::P2SHExtractError)
}

pub fn unlock_utxos(
pub fn unlock_utxos_fee_per_transaction(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be enough to rename the parameter instead of the whole function. But up to you

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and function renaming was reverted.

@aspect aspect merged commit c340bcf into aspectron:pskt-wasm Jul 20, 2024
3 of 6 checks passed
aspect added a commit that referenced this pull request Aug 4, 2024
* TransactionInput signature_script as Option, add associated TS types

* restructure PSKT + WASM scaffolding (WIP)

* Base implementation for PSKB and usage in core account with generator wrapper (#64)

* Base implementation for PSKB and usage in core account with generator wrapper stream handling.

* prune test file

* prune test file

* Converters for transanction and populated transaction.

* Optional signature import in PSKT conversion.

* PSKB wallet cli commands.

* More PSKB wallet cli commands for custom script locks.

* Serialization test case

* Reviews patches, cli script debug command added.

* Doc about fee per transaction for script unlocking UTXOS

* Parameter changed to priority_fee_sompi_per_transaction, revert function renaming.

* Error handling

* Adding type conversion. (#76)

* fmt

* fix WASM32 PSKT function names

* refactor PSKB as a type wrapper + update serialization (#86)

* Cleanup of unused JSON test file for PSKB and comments (#87)

* Remove PSKB json test file.

* Remove/change old PSKB comments and commented out inclusions.

---------

Co-authored-by: 1bananagirl <168954040+1bananagirl@users.noreply.github.com>
aspect added a commit that referenced this pull request Aug 30, 2024
…esolver v2) (kaspanet#506)

* support numeric interface (ip) arg without port in --rpclisten-borsh or --rpclisten-json

* isActive for UtxoProcessor and UtxoContext

* Script utility functions + WASM changelog update

* versioned serialization for wRPC

* spelling

* Refactorize State into PoW (#43)

* Add fromRaw with optional target_bits

* Upload builds as GitHub Artifact

* try moving calculateTarget into PoW class as static funct

* Use FromHex trait

* Make PoW constructor accept IHeader & refactorize some parts

* Lint

* TransactionDataT and BindingT (#44)

* borsh update to 1.5.1

* fix returning receive addr from bindings change addr fn.

* lints

* update WASM changelog

* fix WASM module reference in examples

* migrate lints.clippy to workspace and inherit this in the relevant crates

* Add provisional fields for storage metrics (db size)

* fix file creation timestamp issue on some ext4 file systems (updated via workflow-store::fs)

* bigint values in TransactionRecord (#48)

* change address decoding panics to errors

* update error messaging

* Update for bind/listen compatibility with WRS

* range support added for transactions pagination (#49)

* range support added for transactions pagination

* cargo fmt/clippy

* lints

* WRS 0.13.0

* wallet ergonomics helper functions

* WRS 0.13.1

* WRS 0.13.1 lock

* WRS 0.13.2

* kaspa-wallet (cli) updates (using latest resolver APIs + guide cleanup)

* range support for indexdb store load_range function (#52)

* add balance info to account descriptors, additional wallet connectivity utilities and connect api method changes, export wallet utils in wallet prelude,

* Improve ConnectRequest builder interface

* Allow UtxoEntryReference to be re-integrated from a flat object structure.

* indexdb data maintenance: timestamp fix (#53)

* range support for indexdb store load_range function

* indexdb data maintenance: timestamp fix

* removing unused

* Fix incorrect balance when sending to self

* fix child_number typo

* allow setting custom transaction maturity periods

* fix missing renaming for record.value

* fix typedoc references

* pre-borsh-1-5-1 compat

* testing typedoc

* testing typedoc

* lock typedoc to 0.25.8

* disable typedoc treatWarningsAsErrors

* deps

* WIP SPK WASM

* Cargo.lock

* SPK raw object cast + fix return of ISerializableTransaction

* fix le to be when parsing SPK hex version

* remove string version parsing from SPK

* update WASM SDK changelog

* incorrect balance issue (#55)

* TransactionInput signature_script as Option, add associated TS types

* restructure PSKT + WASM scaffolding (WIP)

* wallet guard implementation to block concurrent async access to account operations

* tx serialization example

* change struct serialization version fields from u32 to u16

* WIP - decoupling RPC type aliases (#45)

* Provisional RpcConnection propagation via RpcApi methods (#46)

* provisional RpcConnection propagation via RpcApi methods

* lints

* change api version handling affecting get_server_info_call

* Wallet watch-only accounts (#59)

* Prints extended public keys on export mnemonic command (feature of go kaspawallet).

* Watch-only account implementation for bip32 and multisig kind of accounts with new command account import watchonly.

* Refactor code for less variables.

* Patch import type for command.

* CLI Support for watch only accounts in select account with args function.

* Function sig_op_count equals implemented.

* Helper function in wallet to format XPUB according to network. Converter NetworkId for Prefix. BIP32-Watch Account renamed from WatchOnly, multisig feature removed. Multisig account import as watch-only command added.

* cli watch-only header in list and select.

* Resolve merge.

* update resolver to use v2 API

* change default resolver subdomains

* resolver v2 updates

* Refactorize some addresses and Script related parts (#61)

* Refactorize some addresses and Script related parts

* A ScriptBuilder example on TypeScript

* addOps Opcodes are now BinaryT

* Move txscript bindings to relevant folders

* Sort lines of deps and imports

* Lint

* fix wasm subscribe_daa_score

* expose native RpcClient multiplexer in KaspaRpcClient

* WIP (local wRPC)

* breakdown wRPC serialization trait into two ser/de; improve future compatibility patterns;

* get_connections_call() RPC method + provisional metrics dictionary

* change get_connections() to return the actual value instead of Response struct.

* priorityEntries implementation for tx generator

* fix transaction WASM interface types affecting some function returns

* input and output types on transactions (WASM)

* rpc caps

* update client resolver resolution

* GetSystemInfo RPC call

* make priorityEntries optional in the TS interface definition

* merge cli-resolver

* remove resolver crate from workspace (move to https://github.com/aspectron/kaspa-resolver)

* WRS 0.14.0

* fix merge mishap

* refactor systeminfo + update resolver target generation

* Custom input signatureScript ability (#69)

* Refactorize some addresses and Script related parts

* A ScriptBuilder example on TypeScript

* addOps Opcodes are now BinaryT

* Move txscript bindings to relevant folders

* Sort lines of deps and imports

* Lint

* Prototype of custom sighash operations

* Experimental

* Add SighashType enum and option on SignInput

* Format and a small fix

* Clippy

* hex view for ScriptBuilder (#67)

* add git_hash to system_id

* add git_hash to system_id

* wip

* wip

* refactor git head fetch to use build.rs

* comment

* split utils/sysinfo into utils/git, refactor utils/build.rs to run git to obtain hashes (in addition to file check)

* using WalletGuard, account guard (#73)

1) private context issue on legacy accounts
2) optional url option handling on rpc client connect method
3) using `WalletGuard` type instead of `AsyncMutexGuard`

* add short hash to sysinfo, return short hash in GetSystemInfo

* add contributor DNS seeders (gerri and H@H)

* Update phrase.rs (#74)

* Base implementation for PSKB and usage in core account with generator wrapper (#64)

* Base implementation for PSKB and usage in core account with generator wrapper stream handling.

* prune test file

* prune test file

* Converters for transanction and populated transaction.

* Optional signature import in PSKT conversion.

* PSKB wallet cli commands.

* More PSKB wallet cli commands for custom script locks.

* Serialization test case

* Reviews patches, cli script debug command added.

* Doc about fee per transaction for script unlocking UTXOS

* Parameter changed to priority_fee_sompi_per_transaction, revert function renaming.

* Error handling

* fix missing RPC refs

* Update resolver config (WIP)

* add version to GetSystemInfoResponse

* fix git version handling

* update client-side resolver properties to match current structs

* update resolvers

* fix kaspa-utils/build.rs to always produce git related env vars.

* add git commit hash to WASM32 SDK artifacts during CI build

* fix WASM32 CI build (testing)

* fix the default url handling in wRPC client

* Key attributes (make XPrv and XPub inspectable) (#77)

* getters for XPrv and XPub attributes

* fmt

* post merge fixes

* Merge RBF (#80)

* Replace by fee on mempool (kaspanet#499)

* Replace by fee on mempool with tests

* Add a custom RemovalReason -- ReplacedByFee

* Let `MinerManager` handle replace by fee (RBF) for RPC and P2P

* Refines success conditions and process of RBF policies

* Add an RPC `submit_transaction_replacement` method

* fix fmt

* Fix CLI Build WASM32 error

* Avoid breaking wRPC

* Extend some tests coverage to all priority, orphan & RBF policy combinations

* Let RBF fail early or at least before checking transaction scripts in consensus

* Cleaning

* More cleaning

* Use contextual instead of compute mass in RBF eviction rule

* Avoid collision with another PR

* Avoid collision with another PR (2)

* Extended test coverage of RBF

* Extended test coverage of RBF (2)

* Rename `TransactionBatchValidationArgs` to `TransactionValidationBatchArgs`

* Add comments

* Assert instead of condition

* Add an `RbfPolicy` parameter to mining manager tx validate_and_insert_... fns

* Infer RBF policy from unorphaned transaction

* Apply the RBF policy to all orphan-related cases

* In Rbf allowed mode, check feerate threshold vs all double spends (i.e., compare to the max)

* Minor hashset optimization

* Rename: fee_per_mass -> feerate

* Use rbf policy arg for post processing step as well

* Renames and comments

* Relaxation: fail gracefully if rbf replaced tx is missing (also fixes an edge case where mempool duplication resulted in this scenario)

* Tx id is appended by the caller anyway

---------

Co-authored-by: Tiram <18632023+tiram88@users.noreply.github.com>
Co-authored-by: Michael Sutton <msutton@cs.huji.ac.il>

* post merge fixes

---------

Co-authored-by: KaffinPX <73744616+KaffinPX@users.noreply.github.com>
Co-authored-by: Tiram <18632023+tiram88@users.noreply.github.com>
Co-authored-by: Michael Sutton <msutton@cs.huji.ac.il>

* createInputSignature() utility function (#79)

* ``signTransactionInput`` and move sign_input to its proper location

* Fix typedoc warnings left from old PR

* createInputSignature

* Update docs for ConsensusParams (WASM mass calc)

* fmt

* bump wRPC

* wrs 0.15.0

* replace Uuid.as_ref() to as_bytes()

* assign RpcApiOps variants numerical values

* cleanup

* Remove WASM32 mass calculator + change createTransaction() signature (#81)

* Kip9 updates to WASM/wallet framework mass calc (#66)

* WIP

* update kip9 processing in WASM mass calculator

* XPrv.toPrivateKey support

* replace lazy_static with OnceLock

* remove NetworkParams Inner

* make signatureScript optional on ITransactionInput (WASM32)

* WIP mass calc (WASM32)

* remove WASM32 mass calc, replace with dedicated functions

* use OnceCell for NetworkParams (wallet-core)

* Update changelog

* fmt

---------

Co-authored-by: Surinder Singh Matoo <surinder83singh@gmail.com>

* change OnceCell to LazyLock in wallet-core utxo settings

* WASM: update signTransaction() signature

* fix TS types and method names

* lints

* split GetConnections counter into separate clients and peers variables

* fix missing version in GetConnections method

* Adding type conversion. (#76)

* fmt

* refactor kaspa-metrics to expose some internal methods (needed for external processing).

* Word count (#83)

* Update phrase.rs

* private context issue for importing legacy wallet

* account filter updated for calculating account_index

* gen1 decrypt_mnemonic updated for error unwraping

* adding resolver tls option

* cleanup

* Improve input signature capability (#85)

* ``signTransactionInput`` and move sign_input to its proper location

* Fix typedoc warnings left from old PR

* createInputSignature

* Fix createInputSignature and improve PendingTransaction Inputs DX

* Format

* A small Omega change applied to existing code

* Pass reference of transaction in createInputSignature

* fix WASM32 PSKT function names

* refactor PSKB as a type wrapper + update serialization (#86)

* Cleanup of unused JSON test file for PSKB and comments (#87)

* Remove PSKB json test file.

* Remove/change old PSKB comments and commented out inclusions.

* PSKB+PSKT merge with omega branch (#82)

* TransactionInput signature_script as Option, add associated TS types

* restructure PSKT + WASM scaffolding (WIP)

* Base implementation for PSKB and usage in core account with generator wrapper (#64)

* Base implementation for PSKB and usage in core account with generator wrapper stream handling.

* prune test file

* prune test file

* Converters for transanction and populated transaction.

* Optional signature import in PSKT conversion.

* PSKB wallet cli commands.

* More PSKB wallet cli commands for custom script locks.

* Serialization test case

* Reviews patches, cli script debug command added.

* Doc about fee per transaction for script unlocking UTXOS

* Parameter changed to priority_fee_sompi_per_transaction, revert function renaming.

* Error handling

* Adding type conversion. (#76)

* fmt

* fix WASM32 PSKT function names

* refactor PSKB as a type wrapper + update serialization (#86)

* Cleanup of unused JSON test file for PSKB and comments (#87)

* Remove PSKB json test file.

* Remove/change old PSKB comments and commented out inclusions.

---------

Co-authored-by: 1bananagirl <168954040+1bananagirl@users.noreply.github.com>

* extra new line char removed (#89)

* lock issue on wallet creation (#91)

* wasm cast refs

* resolver updates

* CLI review: import cli watch-only changed to watch, PSKB parse view added (#92)

* CLI - Import commands for watch-only accounts changed to: account watch bip32 and account watch multisig.

* CLI - PSKB parse view added next to debug view showing input/output addresses and amounts. PSKT finalized check moved from debug view to parse view. Selected account requirement in commands only if needed.

* WASM RBF (RPC)

* WASM FeeEstimate (RPC)

* hex encoding for kaspa_utils::SystemInfo

* Some symmetry and type fixes (#93)

* UtxoEntry typing fix and isometry w UtxoEntryReference

* Fix type of IUtxoProcessorEvent

* Fix interface typings of UtxoProcessor

* Remove UtxoProcessorEventData and improve UtxoProcessor event

* Remove unneeded overwrite

* Clippy and a small mistake fix

* Note: Clippy can cause fmt issues :nerd:

* update WASM GeneratorSettings::priorityEntries? to accept UtxoEntryReference[]

* WASM32 - update resolver casting

* cleanup

* WASM32: remove no longer used WAPI account module

* cleanup

* introduce new rpc header/block types for BBT and SB (#95)

* introduce new rpc header/block types for BBT and SB

* remove unneeded clone

* WASM - Update types for Mnemonic::random()

* WASM update deprecated methods in web-sys

* Add bip32 Mnemonic class to kaspa-wasm-sdk-keys build package

* misc dependency updates

* Introduce profile data to GetConnections RPC method

* WASM update TS declarations for wallet events

* fix WASM sdk submitTransaction API (#96)

* Add custom Debug to GetSystemInfoResponse

* Add HexString type to ITransactionOutput::scriptPublicKey

* fix camelCase on RpcTransactionOutpoint

---------

Co-authored-by: KaffinPX <73744616+KaffinPX@users.noreply.github.com>
Co-authored-by: surinder singh <surinder83singh@gmail.com>
Co-authored-by: 1bananagirl <168954040+1bananagirl@users.noreply.github.com>
Co-authored-by: Tiram <18632023+tiram88@users.noreply.github.com>
Co-authored-by: Michael Sutton <msutton@cs.huji.ac.il>
Co-authored-by: IgorKhomenko <70977170+IgorKhomenko@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants