1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (C) 2021 Mangata team
#![cfg_attr(not(feature = "std"), no_std)]

use codec::alloc::string::{String, ToString};
use sp_std::vec::Vec;

sp_api::decl_runtime_apis! {
	pub trait MetamaskSignatureRuntimeApi{
		fn get_eip712_sign_data( call: Vec<u8>) -> String;
	}
}

pub fn eip712_payload(method: String, params: String) -> String {
	let input = r#"{
					"types": {
						"EIP712Domain": [
						{
							"name": "name",
							"type": "string"
						},
						{
							"name": "version",
							"type": "string"
						},
						{
							"name": "chainId",
							"type": "uint256"
						},
						{
							"name": "verifyingContract",
							"type": "address"
						}
						],
						"Message": [
						{
							"name": "method",
							"type": "string"
						},
						{
							"name": "params",
							"type": "string"
						},
						{
							"name": "tx",
							"type": "string"
						}
						]
					},
					"primaryType": "Message",
					"domain": {
						"name": "Mangata",
						"version": "1",
						"chainId": "5",
						"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
					},
					"message": {
						"method": "",
						"params": "",
						"tx": ""
					}
				}"#;
	if let Ok(ref mut v) = serde_json::from_str::<serde_json::Value>(input) {
		v["message"]["method"] = serde_json::Value::String(method);
		v["message"]["params"] = serde_json::Value::String(params);
		v.to_string()
	} else {
		Default::default()
	}
}