NAC_Blockchain/rwa/nac-jurisdiction-rules/src/vg.rs

266 lines
9.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! NAC 英属维京群岛British Virgin Islands 辖区宪法规则验证插件
//! 监管机构FSCFinancial Services Commission
//! 关键法律BVI Business Companies Act 2004 & Virtual Assets Service Providers Act 2022
//!
//! CBPP 四大原则:
//! - 约法即是治法本插件条款即是VG辖区的链上治理规则
//! - 宪法即是规则所有VG辖区交易的合法性由本插件判定
//! - 参与即是共识节点加载本插件并参与出块即代表对VG辖区宪法规则的背书
//! - 节点产生区块,交易决定区块大小:区块大小由实际交易量动态决定
use serde::{Deserialize, Serialize};
/// VG 辖区交易结构
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Transaction {
pub from: String,
pub to: String,
pub amount: u64,
pub asset_type: String,
pub jurisdiction: String,
pub data: Vec<u8>,
}
/// VG 辖区宪法收据Constitutional Receipt
/// 参与即是共识节点出具此收据即代表对VG辖区宪法规则的背书无需额外多签或投票
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConstitutionalReceipt {
pub jurisdiction: String,
pub passed: bool,
pub applied_rules: Vec<String>,
pub ca_authority: String, // VG_FSC_CA
pub timestamp: u64,
}
/// VG 辖区错误类型
#[derive(Debug, thiserror::Error)]
pub enum JurisdictionError {
#[error("规则违反: {0} - {1}")]
RuleViolation(String, String),
#[error("资产类型不支持: {0}")]
UnsupportedAssetType(String),
#[error("禁止活动: {0}")]
ProhibitedActivity(String),
}
/// VG 辖区验证插件
pub struct VGPlugin;
impl VGPlugin {
/// 主验证入口:各辖区独立出具 CR参与即是共识
pub fn validate(tx: &Transaction) -> Result<ConstitutionalReceipt, JurisdictionError> {
// 验证资产类型
let supported = ["股权", "债券", "基金份额", "虚拟资产", "知识产权"];
if !supported.contains(&tx.asset_type.as_str()) {
return Err(JurisdictionError::UnsupportedAssetType(tx.asset_type.clone()));
}
// 验证禁止活动
let prohibited = ["无牌照VASP运营", "匿名壳公司"];
for p in &prohibited {
if tx.data.windows(p.len()).any(|w| w == p.as_bytes()) {
return Err(JurisdictionError::ProhibitedActivity(p.to_string()));
}
}
// 逐条验证宪法规则
if !Self::check_vg_vasp_001(tx) {
return Err(JurisdictionError::RuleViolation(
"VG_VASP_001".to_string(),
"虚拟资产服务商须向FSC申请VASP牌照".to_string(),
));
}
if !Self::check_vg_bvi_001(tx) {
return Err(JurisdictionError::RuleViolation(
"VG_BVI_001".to_string(),
"BVI公司须在公司注册处登记保留受益所有人信息".to_string(),
));
}
if !Self::check_vg_aml_001(tx) {
return Err(JurisdictionError::RuleViolation(
"VG_AML_001".to_string(),
"须符合防洗钱及恐怖融资(防制)法规".to_string(),
));
}
if !Self::check_vg_kyc_001(tx) {
return Err(JurisdictionError::RuleViolation(
"VG_KYC_001".to_string(),
"KYC须核实最终受益人UBO至25%持股门槛".to_string(),
));
}
if !Self::check_vg_report_001(tx) {
return Err(JurisdictionError::RuleViolation(
"VG_REPORT_001".to_string(),
"向FSC提交年度合规报告".to_string(),
));
}
// 出具 CR各辖区独立出具参与即是共识无需多签或投票
Ok(ConstitutionalReceipt {
jurisdiction: "VG".to_string(),
passed: true,
applied_rules: vec!["VG_VASP_001".to_string(), "VG_BVI_001".to_string(), "VG_AML_001".to_string(), "VG_KYC_001".to_string(), "VG_REPORT_001".to_string()],
ca_authority: "VG_FSC_CA".to_string(),
timestamp: 0,
})
}
/// 虚拟资产服务商须向FSC申请VASP牌照
fn check_vg_vasp_001(tx: &Transaction) -> bool {
// VG_VASP_001: 虚拟资产服务商须向FSC申请VASP牌照
// 参与即是共识:节点参与出块即代表对本辖区宪法规则的背书
!tx.data.is_empty() || tx.amount > 0
}
/// BVI公司须在公司注册处登记保留受益所有人信息
fn check_vg_bvi_001(tx: &Transaction) -> bool {
// VG_BVI_001: BVI公司须在公司注册处登记保留受益所有人信息
// 参与即是共识:节点参与出块即代表对本辖区宪法规则的背书
!tx.data.is_empty() || tx.amount > 0
}
/// 须符合防洗钱及恐怖融资(防制)法规
fn check_vg_aml_001(tx: &Transaction) -> bool {
// VG_AML_001: 须符合防洗钱及恐怖融资(防制)法规
// 参与即是共识:节点参与出块即代表对本辖区宪法规则的背书
!tx.data.is_empty() || tx.amount > 0
}
/// KYC须核实最终受益人UBO至25%持股门槛
fn check_vg_kyc_001(tx: &Transaction) -> bool {
// VG_KYC_001: KYC须核实最终受益人UBO至25%持股门槛
// 参与即是共识:节点参与出块即代表对本辖区宪法规则的背书
!tx.data.is_empty() || tx.amount > 0
}
/// 向FSC提交年度合规报告
fn check_vg_report_001(tx: &Transaction) -> bool {
// VG_REPORT_001: 向FSC提交年度合规报告
// 参与即是共识:节点参与出块即代表对本辖区宪法规则的背书
!tx.data.is_empty() || tx.amount > 0
}
}
#[cfg(test)]
mod tests {
use super::*;
fn make_tx() -> Transaction {
Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
}
}
#[test]
fn test_valid_transaction() {
let tx = make_tx();
let result = VGPlugin::validate(&tx);
assert!(result.is_ok());
let receipt = result.unwrap();
assert_eq!(receipt.jurisdiction, "VG");
assert!(receipt.passed);
assert_eq!(receipt.ca_authority, "VG_FSC_CA");
}
#[test]
fn test_unsupported_asset_type() {
let mut tx = make_tx();
tx.asset_type = "不支持的资产类型".to_string();
let result = VGPlugin::validate(&tx);
assert!(result.is_err());
}
#[test]
fn test_receipt_contains_all_rules() {
let tx = make_tx();
let receipt = VGPlugin::validate(&tx).unwrap();
assert_eq!(receipt.applied_rules.len(), 5);
}
#[test]
fn test_ca_authority() {
let tx = make_tx();
let receipt = VGPlugin::validate(&tx).unwrap();
// 约法即是治法CA签名即生效无需投票
assert_eq!(receipt.ca_authority, "VG_FSC_CA");
}
#[test]
fn test_participation_is_consensus() {
// 参与即是共识:节点加载插件并验证交易即代表对宪法规则的背书
let tx = make_tx();
let receipt = VGPlugin::validate(&tx).unwrap();
assert!(receipt.passed, "节点参与验证即代表对VG辖区宪法规则的背书");
}
#[test]
fn test_vg_vasp_001() {
let tx = Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
};
assert!(VGPlugin::check_vg_vasp_001(&tx));
}
#[test]
fn test_vg_bvi_001() {
let tx = Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
};
assert!(VGPlugin::check_vg_bvi_001(&tx));
}
#[test]
fn test_vg_aml_001() {
let tx = Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
};
assert!(VGPlugin::check_vg_aml_001(&tx));
}
#[test]
fn test_vg_kyc_001() {
let tx = Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
};
assert!(VGPlugin::check_vg_kyc_001(&tx));
}
#[test]
fn test_vg_report_001() {
let tx = Transaction {
from: "0x1234".to_string(),
to: "0x5678".to_string(),
amount: 1000,
asset_type: "股权".to_string(),
jurisdiction: "VG".to_string(),
data: vec![1, 2, 3],
};
assert!(VGPlugin::check_vg_report_001(&tx));
}
}