-
Notifications
You must be signed in to change notification settings - Fork 136
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
Slate binary/base64 encoding #112
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1d360e8
Add encode() method to VersionedSlate
mcdallas 5d5befb
rustfmt
mcdallas 2a8882d
add StdioWalletCommAdapter
mcdallas 3bedd12
rustfmt
mcdallas ea77598
add Slate.from_bytes()
mcdallas 3264ccc
rustfmt
mcdallas 92fafa3
add "string" method to grin-wallet finalize
mcdallas 2786fb8
add 'string' method to 'send' and 'receive'
mcdallas a73549b
rustfmt
mcdallas b6560ed
Move encoding to a trait of Slate
mcdallas 2a78450
rustfmt
mcdallas 4e5d6f9
fix tests
mcdallas 46ec60f
rebase on milestone/2.0.0 and fix conflicts
mcdallas f47e6ee
use PublicKey::read/write
mcdallas c81baf1
use compact encoding for signatures instead of raw bytes
mcdallas 92c361f
rustfmt
mcdallas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2018 The Grin Developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Standard Input/Output 'plugin' implementation | ||
use std::io::{stdin, Read}; | ||
|
||
use crate::base64; | ||
use crate::config::WalletConfig; | ||
use crate::libwallet::{Error, ErrorKind, Slate}; | ||
use crate::WalletCommAdapter; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Clone)] | ||
pub struct StdioWalletCommAdapter {} | ||
|
||
impl StdioWalletCommAdapter { | ||
/// Create | ||
pub fn new() -> Box<dyn WalletCommAdapter> { | ||
Box::new(StdioWalletCommAdapter {}) | ||
} | ||
} | ||
|
||
impl WalletCommAdapter for StdioWalletCommAdapter { | ||
fn supports_sync(&self) -> bool { | ||
false | ||
} | ||
|
||
fn send_tx_sync(&self, _dest: &str, _slate: &Slate) -> Result<Slate, Error> { | ||
unimplemented!(); | ||
} | ||
|
||
fn send_tx_async(&self, _dest: &str, slate: &Slate) -> Result<(), Error> { | ||
let bytes = slate.to_bytes()?; | ||
println!("{}", base64::encode(&bytes)); | ||
Ok(()) | ||
} | ||
|
||
fn receive_tx_async(&self, params: &str) -> Result<Slate, Error> { | ||
let params = params.trim(); | ||
// if user passed the string as input decode that, else | ||
// read from stdin | ||
let b64string = match params { | ||
"" => { | ||
let mut stream = stdin(); | ||
let mut content = String::new(); | ||
stream.read_to_string(&mut content)?; | ||
content | ||
} | ||
_ => params.to_owned(), | ||
}; | ||
|
||
let bytes = base64::decode(b64string.as_bytes()).map_err(|_| ErrorKind::SlateDeser)?; | ||
let slate = Slate::from_bytes(&bytes)?; | ||
Ok(slate) | ||
} | ||
|
||
fn listen( | ||
&self, | ||
_params: HashMap<String, String>, | ||
_config: WalletConfig, | ||
_passphrase: &str, | ||
_account: &str, | ||
_node_api_secret: Option<String>, | ||
) -> Result<(), Error> { | ||
unimplemented!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our plan is to deprecate "file" then, right? I can't think of any reason we would want file support when we have something as simple as a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand, why would we want to deprecate the ability to save a slate as a file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fully replaces every use case for file send/receive. One of our many usability issues right now is the fact that there are so many different ways to send/receive grin. Certain exchanges only support certain methods, and the same goes for wallets. It may sound counter-intuitive, but the way we make grin more usable is to support fewer transfer methods, not more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not with you here. Are you suggesting that anyone using the command line wallet should have to cut and paste strings into the command line instead of being allowed to specify a file name, and everyone creating a new transaction for email send (for instance) would either have to cut/paste or pipe output into a file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, seems easy enough. Regardless, I'm not as worried about the 'file' method as having a separate serialization format for files. If we're going to serialize slates to base64 for files too, then I'm ok with keeping it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can keep the file as is for now and have it output a hex or b64 file after the hard fork