Skip to content

Commit 376c3b1

Browse files
committed
feat(rad): RadonBytesEncoding::Base58
1 parent bc46d4f commit 376c3b1

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rad/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tokio = "1.44.1"
1515
[dependencies]
1616
anyhow = "1.0.98"
1717
base64 = "0.22.1"
18+
bs58 = "0.5.1"
1819
cbor-codec = { git = "https://github.com/witnet/cbor-codec.git", branch = "feat/ldexpf-shim" }
1920
futures = "0.3.31"
2021
hex = "0.4.1"

rad/src/operators/bytes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub fn to_string(input: &RadonBytes, args: &Option<Vec<Value>>) -> Result<RadonS
9090
}
9191
match bytes_encoding {
9292
RadonBytesEncoding::Hex => RadonString::try_from(Value::Text(hex::encode(input.value()))),
93+
RadonBytesEncoding::Base58 => RadonString::try_from(Value::Text(bs58::encode(input.value()).into_string())),
9394
RadonBytesEncoding::Base64 => RadonString::try_from(Value::Text(
9495
base64::engine::general_purpose::STANDARD.encode(input.value()),
9596
)),

rad/src/operators/string.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ pub fn as_bytes(input: &RadonString, args: &Option<Vec<Value>>) -> Result<RadonB
6565
to: "RadonBytes",
6666
})?,
6767
)),
68+
RadonBytesEncoding::Base58 => Ok(RadonBytes::from(
69+
bs58::decode(input.value())
70+
.into_vec()
71+
.map_err(|_err| RadError::Decode {
72+
from: "RadonString",
73+
to: "RadonBytes",
74+
})?,
75+
)),
6876
RadonBytesEncoding::Base64 => Ok(RadonBytes::from(
6977
base64::engine::general_purpose::STANDARD
7078
.decode(input.value())

rad/src/types/bytes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ const RADON_BYTES_TYPE_NAME: &str = "RadonBytes";
2020
#[repr(u8)]
2121
pub enum RadonBytesEncoding {
2222
#[default]
23-
Hex = 0,
24-
Base64 = 1,
25-
Utf8 = 2,
23+
Hex = 0x00,
24+
Base58 = 0x10,
25+
Base64 = 0x11,
26+
Utf8 = 0x80,
2627
}
2728

2829
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]

0 commit comments

Comments
 (0)