Massive changes. I dont know what happens. Rewrote the action wizard again. Fixed several bugs related to the utxo selection. QR codes were added for address. Add support for data results. Experiment with other methods of role extraction
This commit is contained in:
@@ -68,6 +68,55 @@ export class HistoryService {
|
||||
private invitations: Invitation[]
|
||||
) {}
|
||||
|
||||
async extractEntities(invitation: XOInvitation): Promise<string[]> {
|
||||
const entities = new Set<string>();
|
||||
for (const commit of invitation.commits) {
|
||||
entities.add(commit.entityIdentifier);
|
||||
}
|
||||
return Array.from(entities);
|
||||
}
|
||||
|
||||
// Entities are currently static per invitation. So, we can try to match the roles to entities by:
|
||||
// Iterating through each commit, extract the entity into a Map<entityId: string, roles: string[]>.
|
||||
// While we iterate through the commits, if we see a role declaration in the commit, we save that role onto the entity's roles array.
|
||||
// After we have iterated through all the commits, we can return the Map<entityId: string, roles: string[]>.
|
||||
async matchRolesToEntities(invitation: XOInvitation, entities: string[]): Promise<Record<string, string[]>> {
|
||||
const entitiesMap = new Map<string, Set<string>>();
|
||||
for (const entity of entities) {
|
||||
entitiesMap.set(entity, new Set());
|
||||
}
|
||||
|
||||
// First pass, we are just going to try and find roleIdentifer values in the inputs, outputs, and variables.
|
||||
// TODO: Update this once the invitations use XPubs
|
||||
for (const commit of invitation.commits) {
|
||||
const entity = commit.entityIdentifier;
|
||||
const roles = entitiesMap.get(entity) ?? new Set();
|
||||
|
||||
for (const input of commit.data.inputs ?? []) {
|
||||
if (input.roleIdentifier) roles.add(input.roleIdentifier);
|
||||
}
|
||||
for (const output of commit.data.outputs ?? []) {
|
||||
if (output.roleIdentifier) roles.add(output.roleIdentifier);
|
||||
}
|
||||
for (const variable of commit.data.variables ?? []) {
|
||||
if (variable.roleIdentifier) roles.add(variable.roleIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We might be able to use the lockingBytecodes that we have generated to infer which role we are. But the templates dont tell us which role is responsible for a particular output.
|
||||
// I.e, if we dont know what role an output was from, we cant match it using the lockingBytecode to a role.
|
||||
// Example: 2 inputs to a TX for the same amount. We dont know whether we would be Sender1 or Sender2.
|
||||
// So, for now we are just going to rely on the roleIdentifiers that we have found in the first pass.
|
||||
|
||||
// Format into a record for easier access.
|
||||
const entitiesRecord: Record<string, string[]> = {};
|
||||
for (const [entity, roles] of entitiesMap.entries()) {
|
||||
entitiesRecord[entity] = Array.from(roles);
|
||||
}
|
||||
|
||||
return entitiesRecord;
|
||||
}
|
||||
|
||||
async getHistory(): Promise<HistoryItem[]> {
|
||||
const allUtxos = await this.engine.listUnspentOutputsData();
|
||||
const ownOutpoints = new Set<string>();
|
||||
@@ -94,6 +143,10 @@ export class HistoryService {
|
||||
walletEntityIdentifier,
|
||||
});
|
||||
this.indexInvitationOutputsByUtxoOrigin(invitationByOrigin, invitation);
|
||||
|
||||
const entities = await this.extractEntities(invitation.data);
|
||||
const entitiesRecord = await this.matchRolesToEntities(invitation.data, entities);
|
||||
console.log(entitiesRecord);
|
||||
}
|
||||
|
||||
const usedUtxoIds = new Set<string>();
|
||||
@@ -288,6 +341,13 @@ export class HistoryService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This is completely incorrect. It should be deriving the roles of the user based on the entity IDs in the commits, then mapping each commit to Inputs/Outputs so we know what belongs to the user.
|
||||
* There are a few changes that will need to be made to make this work:
|
||||
* 1. Provide a way to derive all entity IDs of the user for the invitation (If we are going with XPub)
|
||||
* 2. Provide a way to get only the User's commits (and their inputs/outputs)
|
||||
* 3. (Maybe) Include role on inputs and outputs - This one might be fine with just using the commit entity id
|
||||
*/
|
||||
private deriveWalletRolesForInvitation(
|
||||
context: InvitationContext,
|
||||
outputs: HistoryUtxoItem[]
|
||||
|
||||
Reference in New Issue
Block a user