我在一个区块链上有一个对象,它会不时地被更新。我想追踪这些变化。我如何描述这样一个结构Vec<(u32, u32)>并在开始时初始化它?现在我有:
encoding_struct! {
struct AC {
const SIZE = 16;
field s: Vec<u32> [00 => 08]
field o: Vec<u32> [08 => 16]
}
}然后等待一个特殊的空init事务。
message! {
struct TxInitAC {
const TYPE = SERVICE_ID;
const ID = TX_INIT_AC;
const SIZE = 0;
}
}用execute方法
fn execute(&self, view: &mut Fork) {
let mut schema = CurrencySchema { view };
let ac = AC::new(vec![], vec![]);
schema.access_control().push(ac);
}发布于 2017-09-29 13:39:20
在与Gitter上的开发人员进行了交谈之后,我想出了一个解决方案。
要在encoding_struct!中描述复合对象,必须在相应的encoding_struct!中描述每个组件。关于这一问题,应:
encoding_struct! {
struct Pair {
const SIZE = 8;
field s: u32 [00 => 04]
field o: u32 [04 => 08]
}
}
encoding_struct! {
struct AC {
const SIZE = 8;
field inner : Vec<Pair> [00 => 08]
}
}要初始化区块链db,必须在initialize特性中实现Service函数,例如,使用空向量初始化:
impl Service for MService {
//...
fn initialize(&self, fork: &mut Fork) -> Value {
let mut schema = MatrixSchema { view: fork };
let matrix = AC::new(vec![]);
// assume method ac() is implemented for the schema
schema.ac().set(ac);
Value::Null
}
}https://stackoverflow.com/questions/46377392
复制相似问题