Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Update grin dependency (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdm committed Feb 23, 2020
1 parent e59517f commit 73b48da
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 112 deletions.
154 changes: 95 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ failure = "0.1"
futures = "0.1"
gotham = "0.3.0"
gotham_derive = "0.3.0"
grin_api = "2.0.0"
grin_core = "2.0.0"
grin_keychain = "2.0.0"
grin_store = "2.0.0"
grin_util = "2.0.0"
grin_api = "3.0.0"
grin_core = "3.0.0"
grin_keychain = "3.0.0"
grin_store = "3.0.0"
grin_util = "3.0.0"
hmac = "0.6"
http = "0.1.5"
hyper = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion src/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::is_cli;
use super::Result;
use crate::contacts::DEFAULT_GRINBOX_PORT;
use grin_core::global::ChainTypes;
use grin_util::LoggingConfig;
use grin_util::logger::LoggingConfig;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fs::File;
Expand Down
8 changes: 4 additions & 4 deletions src/contacts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::common::crypto::{
Base58, PublicKey, GRINBOX_ADDRESS_VERSION_MAINNET, GRINBOX_ADDRESS_VERSION_TESTNET,
};
use crate::common::{ErrorKind, Result};
use grin_core::global::is_mainnet;
use grin_core::global::is_floonet;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug, Display};
Expand Down Expand Up @@ -186,10 +186,10 @@ impl Display for KeybaseAddress {
}

pub fn version_bytes() -> Vec<u8> {
if is_mainnet() {
GRINBOX_ADDRESS_VERSION_MAINNET.to_vec()
} else {
if is_floonet() {
GRINBOX_ADDRESS_VERSION_TESTNET.to_vec()
} else {
GRINBOX_ADDRESS_VERSION_MAINNET.to_vec()
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/controller/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use clap::crate_version;
use colored::Colorize;
use failure::Error;
use grin_core::core::amount_to_hr_string;
use grin_core::global::{coinbase_maturity, is_mainnet};
use grin_core::global::{coinbase_maturity, is_floonet};
use grin_util::secp::pedersen::Commitment;
use grin_util::{to_hex, ZeroingString};
use prettytable::format::consts::{FORMAT_NO_BORDER_LINE_SEPARATOR, FORMAT_NO_COLSEP};
Expand Down Expand Up @@ -499,10 +499,7 @@ pub fn proof(
println!(" {}", excess.bright_magenta());
println!("\n{}: this proof should only be considered valid if the kernel is actually on-chain with sufficient confirmations", "WARNING".bright_yellow());
println!("Please use a grin block explorer to verify this is the case. for example:");
let prefix = match is_mainnet() {
true => "",
false => "floonet.",
};
let prefix = if is_floonet() { "floonet." } else { "" };
cli_message!(" https://{}grinscan.net/kernel/{}", prefix, excess);
}

Expand Down
13 changes: 2 additions & 11 deletions src/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ where
slate.amount,
slate.height,
minimum_confirmations,
slate.lock_height,
max_outputs,
change_outputs,
selection_strategy_is_use_all,
&parent_key_id,
)?;
let keychain = wallet.keychain();
let blinding = slate.add_transaction_elements(keychain, &ProofBuilder::new(keychain), elems)?;

slate.fee = fee;
let blinding = slate.add_transaction_elements(keychain, &ProofBuilder::new(keychain), elems)?;

// Create our own private context
let mut context = Context::new(
Expand Down Expand Up @@ -240,7 +238,6 @@ pub fn select_send_tx<T: ?Sized, C, K, B>(
amount: u64,
current_height: u64,
minimum_confirmations: u64,
lock_height: u64,
max_outputs: usize,
change_outputs: usize,
selection_strategy_is_use_all: bool,
Expand Down Expand Up @@ -272,13 +269,9 @@ where
)?;

// build transaction skeleton with inputs and change
let (mut parts, change_amounts_derivations) =
let (parts, change_amounts_derivations) =
inputs_and_change(&coins, wallet, amount, fee, change_outputs)?;

// This is more proof of concept than anything but here we set lock_height
// on tx being sent (based on current chain height via api).
parts.push(build::with_lock_height(lock_height));

Ok((parts, coins, change_amounts_derivations, fee))
}

Expand Down Expand Up @@ -409,8 +402,6 @@ where
// calculate the total across all inputs, and how much is left
let total: u64 = coins.iter().map(|c| c.value).sum();

parts.push(build::with_fee(fee));

// if we are spending 10,000 coins to send 1,000 then our change will be 9,000
// if the fee is 80 then the recipient will receive 1000 and our change will be
// 8,920
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/api/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use failure::Error;
use gotham_derive::StateData;
use grin_core::core::hash::Hashed;
use grin_core::core::{amount_to_hr_string, Transaction};
use grin_core::ser::ser_vec;
use grin_core::ser::{ser_vec, ProtocolVersion};
use grin_keychain::Identifier;
use grin_util::secp::key::PublicKey;
use grin_util::secp::pedersen::Commitment;
Expand Down Expand Up @@ -487,7 +487,7 @@ where
pub fn post_tx(&self, tx: &Transaction, fluff: bool) -> Result<(), Error> {
self.open_and_close(|c| {
let w = c.backend()?;
let tx_hex = to_hex(ser_vec(tx).unwrap());
let tx_hex = to_hex(ser_vec(tx, ProtocolVersion(1)).unwrap());
let res = w.w2n_client().post_tx(&TxWrapper { tx_hex }, fluff);
if let Err(e) = res {
error!("api: post_tx: failed with error: {}", e);
Expand Down
13 changes: 6 additions & 7 deletions src/wallet/backend/lmdb_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ where
Some(i) => to_key_u64(OUTPUT_PREFIX, &mut id.to_bytes().to_vec(), *i),
None => to_key(OUTPUT_PREFIX, &mut id.to_bytes().to_vec()),
};
option_to_not_found(self.db()?.get_ser(&key), &format!("Key Id: {}", id))
option_to_not_found(self.db()?.get_ser(&key), || format!("Key Id: {}", id))
.map_err(|e| e.into())
}

Expand Down Expand Up @@ -340,10 +340,9 @@ where
);
let (blind_xor_key, nonce_xor_key) = private_ctx_xor_keys(self.keychain(), slate_id)?;

let mut ctx: Context = option_to_not_found(
self.db()?.get_ser(&ctx_key),
&format!("Slate id: {:x?}", slate_id.to_vec()),
)?;
let mut ctx: Context = option_to_not_found(self.db()?.get_ser(&ctx_key), || {
format!("Slate id: {:x?}", slate_id.to_vec())
})?;

for i in 0..SECRET_KEY_SIZE {
ctx.sec_key.0[i] = ctx.sec_key.0[i] ^ blind_xor_key[i];
Expand Down Expand Up @@ -382,7 +381,7 @@ where
tx_f.read_to_string(&mut content)?;
let tx_bin = from_hex(content).unwrap();
Ok(Some(
ser::deserialize::<Transaction>(&mut &tx_bin[..]).unwrap(),
ser::deserialize::<Transaction>(&mut &tx_bin[..], ser::ProtocolVersion(1)).unwrap(),
))
}

Expand Down Expand Up @@ -530,7 +529,7 @@ where
.join(filename);
let path_buf = Path::new(&path).to_path_buf();
let mut stored_tx = File::create(path_buf)?;
let tx_hex = to_hex(ser::ser_vec(tx).unwrap());
let tx_hex = to_hex(ser::ser_vec(tx, ser::ProtocolVersion(1)).unwrap());
stored_tx.write_all(&tx_hex.as_bytes())?;
stored_tx.sync_all()?;
Ok(())
Expand Down
48 changes: 32 additions & 16 deletions src/wallet/types/slate/slate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
//! around during an interactive wallet exchange

use super::versions::v2::*;
use super::versions::{CURRENT_SLATE_VERSION, GRIN_BLOCK_HEADER_VERSION};
use super::versions::{CompatKernelFeatures, CURRENT_SLATE_VERSION, GRIN_BLOCK_HEADER_VERSION};
use crate::wallet::ErrorKind;
use blake2_rfc::blake2b::blake2b;
use failure::Error;
use grin_core::core::amount_to_hr_string;
use grin_core::core::committed::Committed;
use grin_core::core::transaction::{
kernel_features, kernel_sig_msg, Input, Output, Transaction, TransactionBody, TxKernel,
Weighting,
Input, KernelFeatures, Output, Transaction, TransactionBody, TxKernel, Weighting,
};
use grin_core::core::verifier_cache::LruVerifierCache;
use grin_core::libtx::proof::ProofBuild;
Expand Down Expand Up @@ -186,17 +185,18 @@ impl Slate {
&mut self,
keychain: &K,
builder: &B,
mut elems: Vec<Box<build::Append<K, B>>>,
elems: Vec<Box<build::Append<K, B>>>,
) -> Result<BlindingFactor, Error>
where
K: Keychain,
B: ProofBuild,
{
// Append to the exiting transaction
if self.tx.kernels().len() != 0 {
elems.insert(0, build::initial_tx(self.tx.clone()));
}
let (tx, blind) = build::partial_transaction(elems, keychain, builder)?;
let tx = self
.tx
.clone()
.replace_kernel(TxKernel::with_features(self.kernel_features()));

let (tx, blind) = build::partial_transaction(tx, elems, keychain, builder)?;
self.tx = tx;
Ok(blind)
}
Expand Down Expand Up @@ -229,12 +229,20 @@ impl Slate {
Ok(())
}

fn kernel_features(&self) -> KernelFeatures {
match self.lock_height {
0 => KernelFeatures::Plain { fee: self.fee },
_ => KernelFeatures::HeightLocked {
fee: self.fee,
lock_height: self.lock_height,
},
}
}

// This is the msg that we will sign as part of the tx kernel.
// Currently includes the fee and the lock_height.
fn msg_to_sign(&self) -> Result<secp::Message, Error> {
// Currently we only support interactively creating a tx with a "default" kernel.
let features = kernel_features(self.lock_height);
let msg = kernel_sig_msg(self.fee, self.lock_height, features)?;
let msg = self.kernel_features().kernel_sig_msg()?;
Ok(msg)
}

Expand Down Expand Up @@ -777,11 +785,16 @@ impl From<&TxKernel> for TxKernelV2 {
fn from(kernel: &TxKernel) -> TxKernelV2 {
let TxKernel {
features,
fee,
lock_height,
excess,
excess_sig,
} = *kernel;
let (features, fee, lock_height) = match features {
KernelFeatures::Plain { fee } => (CompatKernelFeatures::Plain, fee, 0),
KernelFeatures::Coinbase => (CompatKernelFeatures::Coinbase, 0, 0),
KernelFeatures::HeightLocked { fee, lock_height } => {
(CompatKernelFeatures::HeightLocked, fee, lock_height)
}
};
TxKernelV2 {
features,
fee,
Expand Down Expand Up @@ -972,10 +985,13 @@ impl From<&TxKernelV2> for TxKernel {
excess,
excess_sig,
} = *kernel;
let features = match features {
CompatKernelFeatures::Plain => KernelFeatures::Plain { fee },
CompatKernelFeatures::Coinbase => KernelFeatures::Coinbase,
CompatKernelFeatures::HeightLocked => KernelFeatures::HeightLocked { fee, lock_height },
};
TxKernel {
features,
fee,
lock_height,
excess,
excess_sig,
}
Expand Down
7 changes: 7 additions & 0 deletions src/wallet/types/slate/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ impl From<&VersionedSlate> for Slate {
}
}
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum CompatKernelFeatures {
Plain,
Coinbase,
HeightLocked,
}
5 changes: 3 additions & 2 deletions src/wallet/types/slate/versions/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
//! orig_verion: u16,
//! block_header_version: u16

use grin_core::core::transaction::{KernelFeatures, OutputFeatures};
use super::CompatKernelFeatures;
use grin_core::core::transaction::OutputFeatures;
use grin_core::libtx::secp_ser;
use grin_keychain::BlindingFactor;
use grin_util::secp::key::PublicKey;
Expand Down Expand Up @@ -162,7 +163,7 @@ pub struct OutputV2 {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TxKernelV2 {
/// Options for a kernel's structure or use
pub features: KernelFeatures,
pub features: CompatKernelFeatures,
/// Fee originally included in the transaction this proof is for.
#[serde(with = "secp_ser::string_or_u64")]
pub fee: u64,
Expand Down

4 comments on commit 73b48da

@Azad354
Copy link

Choose a reason for hiding this comment

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

Live

@Azad354
Copy link

Choose a reason for hiding this comment

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

Hi

@Azad354
Copy link

Choose a reason for hiding this comment

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

123

@Azad354
Copy link

Choose a reason for hiding this comment

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

اول و اخر نفهمیدیم چیه این

Please sign in to comment.