Skip to content

add additional UTXO info to partially signed tx #1799

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build-tools/codecheck/codecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def check_local_licenses():
template = re.compile('(?:' + r')\n(?:'.join(LICENSE_TEMPLATE) + ')')

ok = True
for path in rs_sources(['wallet/trezor-client']):
for path in rs_sources():
if any(fnmatch.fnmatch(os.path.abspath(path), os.path.abspath(exempted))
for exempted in exempted_files):
continue
Expand Down
30 changes: 29 additions & 1 deletion chainstate/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use common::{
address::{dehexify::to_dehexified_json, Address},
chain::{
tokens::{RPCTokenInfo, TokenId},
ChainConfig, DelegationId, PoolId, TxOutput,
ChainConfig, DelegationId, Destination, PoolId, TxOutput,
},
primitives::{Amount, BlockHeight, Id},
};
Expand Down Expand Up @@ -142,6 +142,15 @@ trait ChainstateRpc {
#[method(name = "staker_balance")]
async fn staker_balance(&self, pool_address: String) -> RpcResult<Option<Amount>>;

/// Returns the pool's decommission destination associated with the given pool address.
///
/// Returns `None` (null) if the pool is not found.
#[method(name = "pool_decommission_destination")]
async fn pool_decommission_destination(
&self,
pool_address: String,
) -> RpcResult<Option<Destination>>;

/// Given a pool defined by a pool address, and a delegation address,
/// returns the amount of coins owned by that delegation in that pool.
#[method(name = "delegation_share")]
Expand Down Expand Up @@ -332,6 +341,25 @@ impl ChainstateRpcServer for super::ChainstateHandle {
)
}

async fn pool_decommission_destination(
&self,
pool_address: String,
) -> RpcResult<Option<Destination>> {
rpc::handle_result(
self.call(move |this| {
let chain_config = this.get_chain_config();
let result: Result<Option<Destination>, _> =
dynamize_err(Address::<PoolId>::from_string(chain_config, pool_address))
.map(|address| address.into_object())
.and_then(|pool_id| dynamize_err(this.get_stake_pool_data(pool_id)))
.map(|pool_data| pool_data.map(|d| d.decommission_destination().clone()));

result
})
.await,
)
}

async fn delegation_share(
&self,
pool_address: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use std::convert::Infallible;

use common::chain::{
partially_signed_transaction::PartiallySignedTransaction,
signature::{inputsig::InputWitness, DestinationSigError, Transactable},
tokens::TokenId,
ChainConfig, DelegationId, Destination, PoolId, SignedTransaction, TxInput, TxOutput,
Expand Down Expand Up @@ -102,7 +101,6 @@ impl<T: Transactable> InputInfoProvider for InputVerifyContextSignature<'_, T> {
// Prevent BlockRewardTransactable from being used here
pub trait SignatureOnlyVerifiable {}
impl SignatureOnlyVerifiable for SignedTransaction {}
impl SignatureOnlyVerifiable for PartiallySignedTransaction {}

pub fn verify_tx_signature<T: Transactable + SignatureOnlyVerifiable>(
chain_config: &ChainConfig,
Expand Down
7 changes: 7 additions & 0 deletions common/src/chain/tokens/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ impl RPCTokenInfo {
Self::NonFungibleToken(_) => 0,
}
}

pub fn token_ticker(&self) -> &[u8] {
match self {
Self::FungibleToken(info) => info.token_ticker.as_bytes(),
Self::NonFungibleToken(info) => info.metadata.ticker.as_bytes(),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, HasValueHint)]
Expand Down
10 changes: 0 additions & 10 deletions common/src/chain/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use partially_signed_transaction::PartiallySignedTransaction;
use thiserror::Error;

use serialization::{DirectDecode, DirectEncode};
Expand All @@ -34,7 +33,6 @@ pub use account_nonce::*;
pub mod utxo_outpoint;
pub use utxo_outpoint::*;

pub mod partially_signed_transaction;
pub mod signed_transaction;

pub mod output;
Expand Down Expand Up @@ -102,14 +100,6 @@ impl Eq for WithId<Transaction> {}
pub enum TransactionCreationError {
#[error("The number of signatures does not match the number of inputs")]
InvalidWitnessCount,
#[error("The number of input utxos does not match the number of inputs")]
InvalidInputUtxosCount,
#[error("The number of destinations does not match the number of inputs")]
InvalidDestinationsCount,
#[error("The number of htlc secrets does not match the number of inputs")]
InvalidHtlcSecretsCount,
#[error("Failed to convert partially signed tx to signed")]
FailedToConvertPartiallySignedTx(PartiallySignedTransaction),
}

impl Transaction {
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/key/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ExtendedPublicKey {
}
}

pub fn from_hardware_public_key(public_key: Secp256k1ExtendedPublicKey) -> Self {
pub fn new(public_key: Secp256k1ExtendedPublicKey) -> Self {
Self {
pub_key: ExtendedPublicKeyHolder::Secp256k1Schnorr(public_key),
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/key/secp256k1/extended_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Secp256k1ExtendedPublicKey {
}
}

pub fn from_hardware_wallet(
pub fn new(
derivation_path: DerivationPath,
chain_code: ChainCode,
public_key: Secp256k1PublicKey,
Expand Down
19 changes: 19 additions & 0 deletions node-daemon/docs/RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,25 @@ EITHER OF
2) null
```

### Method `chainstate_pool_decommission_destination`

Returns the pool's decommission destination associated with the given pool address.

Returns `None` (null) if the pool is not found.


Parameters:
```
{ "pool_address": string }
```

Returns:
```
EITHER OF
1) bech32 string
2) null
```

### Method `chainstate_delegation_share`

Given a pool defined by a pool address, and a delegation address,
Expand Down
4 changes: 4 additions & 0 deletions rpc/types/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ impl RpcString {
self.0
}

pub fn as_bytes(&self) -> &[u8] {
&self.0
}

pub fn try_into_string(self) -> Result<String, (Self, std::str::Utf8Error)> {
String::from_utf8(self.0).map_err(|e| {
let err = e.utf8_error();
Expand Down
1 change: 1 addition & 0 deletions test-rpc-functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ randomness = { path = "../randomness/" }
rpc = { path = "../rpc/" }
serialization = { path = "../serialization" }
subsystem = { path = "../subsystem/" }
wallet-types = { path = "../wallet/types" }

async-trait.workspace = true
futures.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion test-rpc-functions/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use common::{
EpochIndex,
},
output_value::OutputValue,
partially_signed_transaction::PartiallySignedTransaction,
signature::inputsig::{
authorize_hashed_timelock_contract_spend::AuthorizedHashedTimelockContractSpend,
InputWitness,
Expand All @@ -44,6 +43,7 @@ use serialization::{
hex::{HexDecode, HexEncode},
hex_encoded::HexEncoded,
};
use wallet_types::partially_signed_transaction::PartiallySignedTransaction;

use crate::{RpcTestFunctionsError, RpcTestFunctionsHandle};

Expand Down
28 changes: 27 additions & 1 deletion test/functional/test_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ def init_mintlayer_types():
],
},

"TokenAdditionalInfo": {
"type": "struct",
"type_mapping": [
["num_decimals", "u8"],
["ticker", "Vec<u8>"],
]
},

"UtxoAdditionalInfo": {
"type": "enum",
"type_mapping": [
["TokenInfo", "TokenAdditionalInfo"],
["PoolInfo", "(Amount)"],
["AnyoneCanTake", ""], # TODO
],
},

"UtxoWithAdditionalInfo": {
"type": "struct",
"type_mapping": [
["utxo", "TxOutput"],
["additional_info", "Option<UtxoAdditionalInfo>"],
]
},

"StandardInputSignature": {
"type": "struct",
"type_mapping": [
Expand All @@ -219,9 +244,10 @@ def init_mintlayer_types():
"type_mapping": [
["tx", "TransactionV1"],
["witnesses", "Vec<Option<InputWitness>>"],
["input_utxos", "Vec<Option<TxOutput>>"],
["input_utxos", "Vec<Option<UtxoWithAdditionalInfo>>"],
["destinations", "Vec<Option<Destination>>"],
["htlc_secrets", "Vec<Option<[u8; 32]>>"],
["output_additional_infos", "Vec<Option<UtxoAdditionalInfo>>"],
]
},

Expand Down
14 changes: 9 additions & 5 deletions test/functional/wallet_htlc_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ async def async_test(self):
assert_not_in("Tokens", balance)

# issue a valid token
token_id, _ = (await wallet.issue_new_token("XXXX", 2, "http://uri", alice_address))
token_ticker = "XXXX"
token_number_of_decimals = 2
token_id, _ = (await wallet.issue_new_token(token_ticker, token_number_of_decimals, "http://uri", alice_address))
assert token_id is not None
self.log.info(f"new token id: {token_id}")
token_id_hex = node.test_functions_reveal_token_id(token_id)
Expand Down Expand Up @@ -182,9 +184,10 @@ async def async_test(self):
alice_refund_ptx = {
'tx': tx['transaction'],
'witnesses': [None, None],
'input_utxos': alice_htlc_outputs,
'input_utxos': [{'utxo': out, 'additional_info': None} for out in alice_htlc_outputs],
'destinations': [refund_dest_obj, alice_htlc_change_dest],
'htlc_secrets': [None, None]
'htlc_secrets': [None, None],
'output_additional_infos': [None]
}
alice_refund_tx_hex = scalecodec.base.RuntimeConfiguration().create_scale_object('PartiallySignedTransaction').encode(alice_refund_ptx).to_hex()[2:]

Expand All @@ -210,9 +213,10 @@ async def async_test(self):
bob_refund_ptx = {
'tx': tx['transaction'],
'witnesses': [None, None],
'input_utxos': bob_htlc_outputs,
'input_utxos': [{'utxo': out, 'additional_info': None} for out in bob_htlc_outputs],
'destinations': [refund_dest_obj, bob_htlc_change_dest],
'htlc_secrets': [None, None]
'htlc_secrets': [None, None],
'output_additional_infos': [None]
}
bob_refund_tx_hex = scalecodec.base.RuntimeConfiguration().create_scale_object('PartiallySignedTransaction').encode(bob_refund_ptx).to_hex()[2:]

Expand Down
2 changes: 1 addition & 1 deletion wallet/src/account/currency_grouper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum Currency {
Token(TokenId),
}

pub(crate) fn group_outputs<T, Grouped: Clone>(
pub fn group_outputs<T, Grouped: Clone>(
outputs: impl Iterator<Item = T>,
get_tx_output: impl Fn(&T) -> &TxOutput,
mut combiner: impl FnMut(&mut Grouped, &T, Amount) -> WalletResult<()>,
Expand Down
Loading
Loading