Skip to content

Commit

Permalink
feat: change grpc address conversions to use from_str (#6422)
Browse files Browse the repository at this point in the history
Description
---
Chane string conversion to not assume base58. but tries all conversions
using from_str.

Motivation and Context
---
It allows users to give hex, base58 or emoji
  • Loading branch information
SWvheerden authored Jul 23, 2024
1 parent b6642a6 commit 33374a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::{TryFrom, TryInto};
use std::{
convert::{TryFrom, TryInto},
str::FromStr,
};

use futures::{
channel::mpsc::{self, Sender},
Expand Down Expand Up @@ -335,7 +338,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.into_inner()
.recipient
.ok_or_else(|| Status::internal("Request is malformed".to_string()))?;
let address = TariAddress::from_base58(&message.address)
let address = TariAddress::from_str(&message.address)
.map_err(|_| Status::internal("Destination address is malformed".to_string()))?;

let mut transaction_service = self.get_transaction_service();
Expand Down Expand Up @@ -496,7 +499,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.into_iter()
.enumerate()
.map(|(idx, dest)| -> Result<_, String> {
let address = TariAddress::from_base58(&dest.address)
let address = TariAddress::from_str(&dest.address)
.map_err(|_| format!("Destination address at index {} is malformed", idx))?;
Ok((
dest.address,
Expand Down
5 changes: 3 additions & 2 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
cmp,
convert::{TryFrom, TryInto},
str::FromStr,
};

use borsh::{BorshDeserialize, BorshSerialize};
Expand Down Expand Up @@ -843,7 +844,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let mut kernel_message = [0; 32];
let mut last_kernel = Default::default();
for coinbase in coinbases {
let address = TariAddress::from_base58(&coinbase.address)
let address = TariAddress::from_str(&coinbase.address)
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
let range_proof_type = if coinbase.revealed_value_proof {
RangeProofType::RevealedValue
Expand Down Expand Up @@ -1040,7 +1041,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let mut kernel_message = [0; 32];
let mut last_kernel = Default::default();
for coinbase in coinbases {
let address = TariAddress::from_base58(&coinbase.address)
let address = TariAddress::from_str(&coinbase.address)
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
let range_proof_type = if coinbase.revealed_value_proof {
RangeProofType::RevealedValue
Expand Down

0 comments on commit 33374a6

Please sign in to comment.