Completely broken update to latest versions
This commit is contained in:
+31
-14
@@ -15,6 +15,10 @@ import type {
|
||||
} from "@xo-cash/types";
|
||||
import type { UnspentOutputData } from "@xo-cash/state";
|
||||
import {
|
||||
bigIntToBinUint64LE,
|
||||
bigIntToBinUintBE,
|
||||
bigIntToBinUintLE,
|
||||
bigIntToVmNumber,
|
||||
binToHex,
|
||||
encodeTransaction,
|
||||
generateTransaction,
|
||||
@@ -28,7 +32,7 @@ import type { BaseStorage } from "./storage.js";
|
||||
import type { BlockchainService } from "./electrum.js";
|
||||
|
||||
import { EventEmitter } from "../utils/event-emitter.js";
|
||||
import { decodeExtendedJsonObject } from "../utils/ext-json.js";
|
||||
import { decodeExtendedJson, decodeExtendedJsonObject, encodeExtendedJson } from "../utils/ext-json.js";
|
||||
import { compileCashAssemblyString } from "@xo-cash/engine";
|
||||
|
||||
export type InvitationEventMap = {
|
||||
@@ -279,7 +283,8 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
private async computeStatusInternal(): Promise<string> {
|
||||
let missingReqs;
|
||||
try {
|
||||
missingReqs = await this.engine.listMissingRequirements(this.data);
|
||||
const missingRequirements = await this.engine.listMissingRequirements(this.data.invitationIdentifier);
|
||||
missingReqs = missingRequirements.templateRequirements;
|
||||
} catch {
|
||||
return "unknown";
|
||||
}
|
||||
@@ -394,7 +399,7 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
*/
|
||||
async sign(): Promise<void> {
|
||||
// Sign the invitation
|
||||
const signedInvitation = await this.engine.signInvitation(this.data);
|
||||
const signedInvitation = await this.engine.signInvitation(this.data.invitationIdentifier);
|
||||
|
||||
// Publish the signed invitation to the sync server
|
||||
this.publishInvitation(signedInvitation);
|
||||
@@ -413,7 +418,7 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
* @returns The transaction hash returned by the network after broadcast.
|
||||
*/
|
||||
async broadcast(): Promise<string> {
|
||||
const txHash = await this.engine.executeAction(this.data, {
|
||||
const txHash = await this.engine.executeAction(this.data.invitationIdentifier, {
|
||||
broadcastTransaction: true,
|
||||
});
|
||||
|
||||
@@ -431,7 +436,7 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
*/
|
||||
async append(data: AppendInvitationParameters): Promise<void> {
|
||||
// Append the commit to the invitation
|
||||
this.data = await this.engine.appendInvitation(this.data, data);
|
||||
this.data = await this.engine.appendInvitation(this.data.invitationIdentifier, data);
|
||||
|
||||
// Sync the invitation to the sync server
|
||||
await this.publishInvitation(this.data);
|
||||
@@ -546,7 +551,7 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
* Get the missing requirements for the invitation
|
||||
*/
|
||||
async getMissingRequirements() {
|
||||
return this.engine.listMissingRequirements(this.data);
|
||||
return this.engine.listMissingRequirements(this.data.invitationIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,33 +613,41 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
);
|
||||
}
|
||||
|
||||
const valueSatoshisIdentifier = output.valueSatoshis;
|
||||
if (!valueSatoshisIdentifier) {
|
||||
const valueSatoshisExpression = output.valueSatoshis;
|
||||
if (!valueSatoshisExpression) {
|
||||
throw new Error(
|
||||
`Value satoshis identifier not found: ${outputIdentifier} in template: ${this.data.templateIdentifier}`,
|
||||
);
|
||||
}
|
||||
|
||||
console.dir(this.data, { depth: null });
|
||||
|
||||
// Create a list of all the variables from the commits
|
||||
const variables = this.data.commits.flatMap(
|
||||
(c) => c.data?.variables ?? [],
|
||||
);
|
||||
console.dir(variables, { depth: null });
|
||||
|
||||
// Create a dictionary of the variables
|
||||
const formattedVariables = variables.reduce(
|
||||
(acc, v) => {
|
||||
acc[v.variableIdentifier ?? ""] = v.value;
|
||||
const { variableIdentifier, value } = v;
|
||||
console.log(typeof value);
|
||||
acc[variableIdentifier ?? ""] = value;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, XOInvitationVariableValue>,
|
||||
);
|
||||
|
||||
console.dir(formattedVariables, { depth: null });
|
||||
|
||||
// Compile the CashAssembly expression to get the value satoshis (It handles the variable replacement for us)
|
||||
const valueSatoshis = await compileCashAssemblyString(
|
||||
String(valueSatoshisIdentifier),
|
||||
formattedVariables,
|
||||
const valueSatoshis = compileCashAssemblyString(
|
||||
{ cashAssemblyText: String(valueSatoshisExpression), variables: formattedVariables, evaluationDecodeMode: 'bigint' },
|
||||
);
|
||||
|
||||
console.dir(valueSatoshis, { depth: null });
|
||||
|
||||
// Return the value satoshis as a bigint
|
||||
// TODO: Check this of a vulnerability or crash - I assume there might be one if someone made the `valueSatoshis` a malicious expression
|
||||
return BigInt(valueSatoshis);
|
||||
@@ -688,9 +701,13 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
// Iterate through the outputs and sum the valueSatoshis
|
||||
for (const output of outputs) {
|
||||
if (typeof output === "string") {
|
||||
totalSats += await this.getSatsOut(output);
|
||||
const sats = await this.getSatsOut(output);
|
||||
console.log(`Sats for output: ${output} is ${sats}`);
|
||||
totalSats += sats
|
||||
} else {
|
||||
totalSats += await this.getSatsOut(output.output);
|
||||
const sats = await this.getSatsOut(output.output);
|
||||
console.log(`Sats for output: ${output.output} is ${sats}`);
|
||||
totalSats += sats;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user