Skip to content

Commit 6737136

Browse files
authored
Merge pull request #94 from MeshJS/Staking
hf4
2 parents b56b169 + 77b2ee8 commit 6737136

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

src/components/multisig/inspect-multisig-script.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export default function InspectMultisigScript({
4646
label="CBOR"
4747
value={<Code>{mWallet.getPaymentScript()}</Code>}
4848
/>
49+
{appWallet?.stakeCredentialHash && <RowLabelInfo
50+
label="Stake Credential Hash"
51+
value={<Code>{appWallet?.stakeCredentialHash}</Code>}
52+
/>}
4953
</div>,
5054
];
5155

src/components/pages/wallet/info/card-info.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ function EditInfo({
105105
isArchived,
106106
});
107107
}
108-
109108
return (
110109
<fieldset className="grid gap-6">
111110
<div className="grid gap-3">

src/components/pages/wallet/new-transaction/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useRouter } from "next/router";
33

44
import {
55
keepRelevant,
6+
NativeScript,
67
Quantity,
78
Unit,
89
UTxO,
@@ -153,7 +154,7 @@ export default function PageNewTransaction() {
153154

154155
if(!multisigWallet) return
155156

156-
const paymentScript = multisigWallet?.getPaymentScript()
157+
const paymentScript = appWallet.scriptCbor
157158
// const rewardAddress = multisigWallet?.getStakeAddress()
158159
// const stakingScript = multisigWallet?.getStakingScript()
159160

@@ -162,6 +163,7 @@ export default function PageNewTransaction() {
162163
if(!paymentScript) return
163164
console.log(paymentScript)
164165
console.log(multisigWallet.getKeysByRole(0))
166+
console.log(multisigWallet.getScript())
165167

166168
for (const utxo of selectedUtxos) {
167169
txBuilder

src/utils/common.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ import {
1313
import { Address, getDRepIds } from "@meshsdk/core-cst";
1414
import { MultisigKey, MultisigWallet } from "@/utils/multisigSDK";
1515

16-
function addressToNetwork(address:string):number {
17-
return (address.includes("test"))?0:1;
16+
function addressToNetwork(address: string): number {
17+
return address.includes("test") ? 0 : 1;
1818
}
1919

2020
export function buildMultisigWallet(
2121
wallet: DbWallet,
2222
network?: number,
2323
): MultisigWallet | undefined {
24+
console.log(
25+
"buildMultisigWallet - stakeCredentialHash",
26+
wallet.stakeCredentialHash,
27+
);
28+
2429
const keys: MultisigKey[] = [];
2530
if (wallet.signersAddresses.length > 0) {
26-
if(!network) network = addressToNetwork(wallet.signersAddresses[0]!)
31+
if (!network) network = addressToNetwork(wallet.signersAddresses[0]!);
2732
wallet.signersAddresses.forEach((addr, i) => {
2833
if (addr) {
2934
try {
@@ -55,14 +60,22 @@ export function buildMultisigWallet(
5560
}
5661
});
5762
}
58-
if (keys.length === 0) return;
63+
64+
if (keys.length === 0 && !wallet.stakeCredentialHash) {
65+
console.warn(
66+
"buildMultisigWallet: no valid keys and no stakeCredentialHash provided",
67+
wallet,
68+
);
69+
return;
70+
}
71+
const stakeCredentialHash = wallet.stakeCredentialHash as undefined | string;
5972
const multisigWallet = new MultisigWallet(
6073
wallet.name,
6174
keys,
6275
wallet.description ?? "",
6376
wallet.numRequiredSigners ?? 1,
6477
network,
65-
wallet.stakeCredentialHash ?? undefined
78+
stakeCredentialHash,
6679
);
6780
return multisigWallet;
6881
}
@@ -72,6 +85,7 @@ export function buildWallet(
7285
network: number,
7386
utxos?: UTxO[],
7487
): Wallet {
88+
console.log("hi");
7589
const mWallet = buildMultisigWallet(wallet, network);
7690
if (!mWallet) {
7791
console.error("error when building Multisig Wallet!");
@@ -105,8 +119,7 @@ export function buildWallet(
105119
const paymentAddrEmpty =
106120
utxos?.filter((f) => f.output.address === paymentAddress).length === 0;
107121

108-
if (paymentAddrEmpty && mWallet.stakingEnabled()) address = stakeableAddress
109-
122+
if (paymentAddrEmpty && mWallet.stakingEnabled()) address = stakeableAddress;
110123

111124
const dRepIdCip105 = resolveScriptHashDRepId(
112125
resolveNativeScriptHash(nativeScript as NativeScript),

src/utils/multisigSDK.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class MultisigWallet {
3737
keys: MultisigKey[];
3838
required: number;
3939
network: number;
40-
stakeCredentialHash: string;
40+
stakeCredentialHash: string | undefined;
4141

4242
constructor(
4343
name: string,
@@ -59,9 +59,7 @@ export class MultisigWallet {
5959
this.description = description ? description : "";
6060
this.required = required ? required : 1;
6161
this.network = network !== undefined ? network : 1;
62-
this.stakeCredentialHash = stakeCredentialHash
63-
? stakeCredentialHash
64-
: "undefined";
62+
this.stakeCredentialHash = stakeCredentialHash;
6563
}
6664

6765
/**
@@ -87,7 +85,7 @@ export class MultisigWallet {
8785
this.network,
8886
this.stakingEnabled()
8987
? stakeCredentialHash
90-
: this.stakeCredentialHash === "undefined"
88+
: this.stakeCredentialHash === undefined
9189
? undefined
9290
: this.stakeCredentialHash,
9391
this.stakingEnabled(),
@@ -104,7 +102,7 @@ export class MultisigWallet {
104102
);
105103
return undefined;
106104
}
107-
return getScript(paymentScript, this.network).scriptCbor;
105+
return getScript(paymentScript, this.network, ).scriptCbor;
108106
}
109107

110108
getStakingScript(): string | undefined {
@@ -159,8 +157,7 @@ export class MultisigWallet {
159157
* @returns The stake credential hash as a string or undefined if no stake script.
160158
*/
161159
getStakeCredentialHash(): string | undefined {
162-
if (this.stakeCredentialHash !== "undefined")
163-
return this.stakeCredentialHash;
160+
if (this.stakeCredentialHash) return this.stakeCredentialHash;
164161
// Builds script with stake key hashes
165162
const stakeScript = this.buildScript(2);
166163
if (!stakeScript) return undefined;
@@ -274,7 +271,7 @@ function buildNativeScript(
274271
}
275272

276273
/**
277-
* Returns the address of a given multisig script for the specified network.
274+
* Returns the address and cbor of a given multisig script for the specified network.
278275
*
279276
* @param script - The NativeScript.
280277
* @param network - Network identifier (e.g., 1 for mainnet, 0 for testnet).
@@ -291,7 +288,7 @@ function getScript(
291288
script,
292289
stakeCredentialHash,
293290
network,
294-
enabled,
291+
enabled
295292
);
296293
if (!scriptCbor) {
297294
throw new Error("Failed to serialize multisig script");

0 commit comments

Comments
 (0)