initWalletState method
Initialize the wallet state with the given verification key
networkId
The network id to initialize the wallet state with
ledgerId
The ledger id to initialize the wallet state with
vk
The verification key to initialize the wallet state with
Implementation
@override
Future<void> initWalletState(
int networkId, int ledgerId, quivr_shared
.VerificationKey vk) async {
final defaultTemplate = PredicateTemplate(
[SignatureTemplate("ExtendedEd25519", 0)],
1,
);
final genesisTemplate = PredicateTemplate(
[HeightTemplate('header', 1.toInt64, Int64.MAX_VALUE)],
1,
);
// Create parties
await fellowshipsStore.add(
_instance, Fellowship(name: 'nofellowship', xFellowship: 0).toSembast);
await fellowshipsStore.add(
_instance, Fellowship(name: 'self', xFellowship: 1).toSembast);
// Create contracts
await contractsStore.add(
_instance,
Contract(
contract: 'default',
yContract: 1,
lock: jsonEncode(defaultTemplate.toJson()))
.toSembast);
await contractsStore.add(
_instance,
Contract(
contract: 'genesis',
yContract: 2,
lock: jsonEncode(genesisTemplate.toJson()))
.toSembast);
// Create verification keys
await verificationKeysStore.add(
_instance,
sk.VerificationKey(
xFellowship: 1,
yContract: 1,
vks: [Encoding().encodeToBase58Check(vk.writeToBuffer())],
).toSembast); // TODO(ultimaterex): figure out if encoding to stringbase 58 is better
await verificationKeysStore.add(
_instance,
sk.VerificationKey(
xFellowship: 0,
yContract: 2,
vks: [],
).toSembast);
final defaultSignatureLock = getLock("self", "default", 1)!; // unsafe
final signatureLockAddress = LockAddress(
network: networkId,
ledger: ledgerId,
id: LockId(
value: defaultSignatureLock.predicate.sizedEvidence.digest.value));
final childVk = api.deriveChildVerificationKey(vk, 1);
final genesisHeightLock = getLock("nofellowship", "genesis", 1)!; // unsafe
final heightLockAddress = LockAddress(
network: networkId,
ledger: ledgerId,
id: LockId(
value: genesisHeightLock.predicate.sizedEvidence.digest.value));
// Create cartesian coordinates
await cartesiansStore.add(
_instance,
Cartesian(
xFellowship: 1,
yContract: 1,
zState: 1,
lockPredicate: Encoding().encodeToBase58Check(
defaultSignatureLock.predicate.writeToBuffer()),
address: AddressCodecs.encode(signatureLockAddress),
routine: 'ExtendedEd25519',
vk: Encoding().encodeToBase58Check(childVk.writeToBuffer()),
).toSembast);
await cartesiansStore.add(
_instance,
Cartesian(
xFellowship: 0,
yContract: 2,
zState: 1,
lockPredicate: Encoding()
.encodeToBase58Check(genesisHeightLock.predicate.writeToBuffer()),
address: AddressCodecs.encode(heightLockAddress),
).toSembast);
}