-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Nostr address support (#86)
* feat: Introduce np-nostr for Nostr primitive types * feat: Add Nostr address support to frame-babel * test: Fix build errors for tests with all features * test: Add transfer to Nostr address test
- Loading branch information
Showing
11 changed files
with
352 additions
and
14 deletions.
There are no files selected for viewing
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
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,81 @@ | ||
// This file is part of Noir. | ||
|
||
// Copyright (c) Haderech Pte. Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use crate::{mock::*, *}; | ||
use frame_support::{assert_ok, traits::fungible::Inspect}; | ||
use np_babel::EthereumAddress; | ||
use sp_core::ecdsa; | ||
use sp_runtime::traits::AccountIdConversion; | ||
|
||
fn dev_public() -> ecdsa::Public { | ||
const_hex::decode_to_array( | ||
b"02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f", | ||
) | ||
.unwrap() | ||
.into() | ||
} | ||
|
||
#[test] | ||
fn transfer_to_ethereum_address_works() { | ||
let account = AccountId::from(dev_public()); | ||
let address = EthereumAddress::from(dev_public()); | ||
let interim = address.into_account_truncating(); | ||
|
||
new_test_ext().execute_with(|| { | ||
assert_ok!(Babel::transfer( | ||
RuntimeOrigin::signed(alice()), | ||
None, | ||
VarAddress::Ethereum(address), | ||
100 | ||
)); | ||
assert_eq!(Balances::balance(&interim), 100); | ||
assert_eq!(Balances::balance(&account), 0); | ||
|
||
assert_ok!(UnifyAccount::<Test>::unify_ecdsa(&account)); | ||
assert_eq!(Balances::balance(&interim), 0); | ||
assert_eq!(Balances::balance(&account), 100); | ||
}); | ||
} | ||
|
||
#[cfg(feature = "nostr")] | ||
#[test] | ||
fn transfer_to_nostr_address_works() { | ||
use core::str::FromStr; | ||
use np_babel::NostrAddress; | ||
|
||
let account = AccountId::from(dev_public()); | ||
let interim = AccountId::new(dev_public()[1..].try_into().unwrap()); | ||
let address = | ||
NostrAddress::from_str("npub12z25pyvl4t8e4dfpgmy65sxmdqtjmqmhwfgt9rjx0ytkujwvmk0s2yfk08") | ||
.unwrap(); | ||
|
||
new_test_ext().execute_with(|| { | ||
assert_ok!(Babel::transfer( | ||
RuntimeOrigin::signed(alice()), | ||
None, | ||
VarAddress::Nostr(address), | ||
100 | ||
)); | ||
assert_eq!(Balances::balance(&interim), 100); | ||
assert_eq!(Balances::balance(&account), 0); | ||
|
||
assert_ok!(UnifyAccount::<Test>::unify_ecdsa(&account)); | ||
assert_eq!(Balances::balance(&interim), 0); | ||
assert_eq!(Balances::balance(&account), 100); | ||
}); | ||
} |
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,36 @@ | ||
[package] | ||
name = "np-nostr" | ||
version = "0.4.0" | ||
authors = ["Haderech Pte. Ltd."] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/noirhq/noir.git" | ||
publish = false | ||
|
||
[dependencies] | ||
bech32 = { version = "0.11", default-features = false, optional = true } | ||
buidl = { version = "0.1.1", default-features = false, features = ["derive"] } | ||
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.11", default-features = false, features = ["derive"] } | ||
serde = { version = "1.0", default-features = false, optional = true } | ||
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } | ||
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false } | ||
|
||
[dev-dependencies] | ||
const-hex = { version = "1.12", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"bech32/std", | ||
"buidl/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"serde/std", | ||
"sp-core/std", | ||
"sp-runtime/std", | ||
] | ||
serde = [ | ||
"dep:serde", | ||
"bech32/alloc", | ||
] |
Oops, something went wrong.