Skip to content

Commit

Permalink
Merge pull request #35 from peaqnetwork/fix/1202109118228300_bug-the-…
Browse files Browse the repository at this point in the history
…generated-multisig-address-is-wrong

Fix/1202109118228300 Bug: The generated multisig address is wrong
  • Loading branch information
irediaes authored Apr 13, 2022
2 parents 7e6b2f6 + 4df2c3d commit 1dfd0ed
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 30 deletions.
Binary file modified android/app/src/main/jniLibs/arm64-v8a/libpeaq_codec_api.so
Binary file not shown.
Binary file modified android/app/src/main/jniLibs/armeabi-v7a/libpeaq_codec_api.so
Binary file not shown.
Binary file modified android/app/src/main/jniLibs/x86_64/libpeaq_codec_api.so
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/common/providers/peer_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ class CEVPeerProvider with ChangeNotifier {
Future<bool> creatMultisigAddress(String provider, String consumer) async {
// print("creatMultisigAddress hitts");

var data =
await api.createMultisigAddress(provider: provider, consumer: consumer);
var data = await api
.createMultisigAddress(signatories: [provider, consumer], threshold: 2);

var utf8Res = utf8.decode(data);
var decodedRes = json.decode(utf8Res);
Expand Down
32 changes: 17 additions & 15 deletions lib/common/services/fr_bridge/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ abstract class PeaqCodecApi {
dynamic hint});

Future<Uint8List> createMultisigAddress(
{required String consumer, required String provider, dynamic hint});
{required List<String> signatories,
required int threshold,
dynamic hint});

Future<Uint8List> approveMultisig(
{required String wsUrl,
Expand Down Expand Up @@ -141,16 +143,18 @@ class PeaqCodecApiImpl extends FlutterRustBridgeBase<PeaqCodecApiWire>
));

Future<Uint8List> createMultisigAddress(
{required String consumer, required String provider, dynamic hint}) =>
{required List<String> signatories,
required int threshold,
dynamic hint}) =>
executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => inner.wire_create_multisig_address(
port_, _api2wire_String(consumer), _api2wire_String(provider)),
port_, _api2wire_StringList(signatories), _api2wire_u16(threshold)),
parseSuccessData: _wire2api_uint_8_list,
constMeta: const FlutterRustBridgeTaskConstMeta(
debugName: "create_multisig_address",
argNames: ["consumer", "provider"],
argNames: ["signatories", "threshold"],
),
argValues: [consumer, provider],
argValues: [signatories, threshold],
hint: hint,
));

Expand Down Expand Up @@ -446,24 +450,22 @@ class PeaqCodecApiWire implements FlutterRustBridgeWireBase {

void wire_create_multisig_address(
int port_,
ffi.Pointer<wire_uint_8_list> consumer,
ffi.Pointer<wire_uint_8_list> provider,
ffi.Pointer<wire_StringList> signatories,
int threshold,
) {
return _wire_create_multisig_address(
port_,
consumer,
provider,
signatories,
threshold,
);
}

late final _wire_create_multisig_addressPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(ffi.Int64, ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>)>>('wire_create_multisig_address');
late final _wire_create_multisig_address =
_wire_create_multisig_addressPtr.asFunction<
void Function(int, ffi.Pointer<wire_uint_8_list>,
ffi.Pointer<wire_uint_8_list>)>();
ffi.Void Function(ffi.Int64, ffi.Pointer<wire_StringList>,
ffi.Uint16)>>('wire_create_multisig_address');
late final _wire_create_multisig_address = _wire_create_multisig_addressPtr
.asFunction<void Function(int, ffi.Pointer<wire_StringList>, int)>();

void wire_approve_multisig(
int port_,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub fn send_service_requested_event(
}

// Creates a multi signature wallet address
pub fn create_multisig_address(consumer: String, provider: String) -> Result<Vec<u8>> {
let res = request::create_multisig_wallet(consumer, provider).unwrap();
pub fn create_multisig_address(signatories: Vec<String>, threshold: u16) -> Result<Vec<u8>> {
let res = request::create_multisig_wallet(signatories, threshold).unwrap();
Ok(res)
}

Expand Down
10 changes: 5 additions & 5 deletions rust/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub extern "C" fn wire_send_service_requested_event(
#[no_mangle]
pub extern "C" fn wire_create_multisig_address(
port_: i64,
consumer: *mut wire_uint_8_list,
provider: *mut wire_uint_8_list,
signatories: *mut wire_StringList,
threshold: u16,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap(
WrapInfo {
Expand All @@ -101,9 +101,9 @@ pub extern "C" fn wire_create_multisig_address(
mode: FfiCallMode::Normal,
},
move || {
let api_consumer = consumer.wire2api();
let api_provider = provider.wire2api();
move |task_callback| create_multisig_address(api_consumer, api_provider)
let api_signatories = signatories.wire2api();
let api_threshold = threshold.wire2api();
move |task_callback| create_multisig_address(api_signatories, api_threshold)
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn get_event() -> Result<Vec<u8>> {
}

// create multisig account
pub fn create_multisig_wallet(consumer: String, provider: String) -> Result<Vec<u8>> {
pub fn create_multisig_wallet(signatories: Vec<String>, threshold: u16) -> Result<Vec<u8>> {
trace!("\n\n RUST - get_event hitts");

let mut res = ResponseData {
Expand All @@ -61,7 +61,7 @@ pub fn create_multisig_wallet(consumer: String, provider: String) -> Result<Vec<
data: vec![],
};

let address = utils::create_multisig_account(consumer.as_str(), &provider.as_str());
let address = utils::create_multisig_account(signatories, threshold);
res.error = false;
res.message = "Event Found".to_string();
res.data = address.as_bytes().to_vec();
Expand Down
11 changes: 7 additions & 4 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use codec::Compact;
use codec::{Decode, Encode};
// use keyring::sr25519;
use keyring::ed25519;
Expand Down Expand Up @@ -27,11 +28,13 @@ pub fn parse_signatories(address: &str) -> AccountId {
to
}

pub fn create_multisig_account(consumer: &str, provider: &str) -> String {
let who = &mut [consumer.as_bytes().to_vec(), provider.as_bytes().to_vec()];
// &who.sort();
pub fn create_multisig_account(signatories: Vec<String>, threshold: u16) -> String {
let mut signatories: Vec<AccountId> = signatories.iter().map(|si| parse_signatories(si)).collect();

let entropy = (b"modlpy/utilisuba", &who[..].sort(), 2).using_encoded(blake2_256);
let _ = &signatories.sort();
let prefix = b"modlpy/utilisuba";

let entropy = (prefix, signatories, threshold).using_encoded(blake2_256);
trace!("entropy:: {:?}", &entropy);

let multi = AccountId::decode(&mut &entropy[..]).unwrap_or_default();
Expand Down

0 comments on commit 1dfd0ed

Please sign in to comment.