Skip to content

Commit

Permalink
Merge pull request #194 from MeshJS/feature-update/mesh-tx-builder-st…
Browse files Browse the repository at this point in the history
…aking

Feature update/mesh tx builder staking
  • Loading branch information
jinglescode authored Mar 25, 2024
2 parents 1a1b86a + 84f288e commit 8179001
Show file tree
Hide file tree
Showing 16 changed files with 465 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function DeregisterCertificate() {
return (
<Section
sidebarTo="delegateStakeCertificate"
header="Delegate Stake to a Pool"
contentFn={Content()}
/>
);
}

function Content() {
let code = `mesh
.delegateStakeCertificate(stakeKeyHash: string, poolId: string)`;

return (
<>
<p>
Use <code>.delegateStakeCertificate()</code> to delegate a stake to a
pool:
</p>

<Codeblock data={code} isJson={false} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function DeregisterCertificate() {
return (
<Section
sidebarTo="deregisterCertificate"
header="Deregister Stake Certificate"
contentFn={Content()}
/>
);
}

function Content() {
let code = `mesh
.deregisterStakeCertificate(stakeKeyHash: string)`;

return (
<>
<p>
Use <code>.deregisterStakeCertificate()</code> to deregister a stake
certificate:
</p>

<Codeblock data={code} isJson={false} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ export default function Mint() {

function Content() {
let code = `mesh
.mint(quantity: number, policy: string, name: string)
.mint(quantity: string, policy: string, name: string)
.mintingScript(scriptCbor: string)
`;

return (
<>
<h3>When minting tokens using a 'native script' as input, there are 2 steps:</h3>
<h3>
When minting tokens using a 'native script' as input, there are 2 steps:
</h3>
<h4>
1. Providing the minting value (quantity, policy and name) using <code>.mint()</code>
1. Providing the minting value (quantity, policy and name) using{' '}
<code>.mint()</code>
</h4>
<h4>
2. Providing the script source using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Mint() {
function Content() {
let code = `mesh
.mintPlutusScriptV2()
.mint(quantity: number, policy: string, name: string)
.mint(quantity: string, policy: string, name: string)
.mintTxInReference(txHash: string, txIndex: number) // or .mintingScript(scriptCbor: string)
.mintRedeemerValue(redeemer: Data | object | string, exUnits?: Budget, type?: "Mesh" | "CBOR" | "JSON")
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function RegisterCertificate() {
return (
<Section
sidebarTo="registerCertificate"
header="Register Stake Certificate"
contentFn={Content()}
/>
);
}

function Content() {
let code = `mesh
.registerStakeCertificate(stakeKeyHash: string)`;

return (
<>
<p>
Use <code>.registerStakeCertificate()</code> to register a stake
certificate:
</p>

<Codeblock data={code} isJson={false} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function RegisterPoolCertificate() {
return (
<Section
sidebarTo="registerPoolCertificate"
header="Register Pool Certificate"
contentFn={Content()}
/>
);
}

function Content() {
let code = `mesh
.registerPoolCertificate(poolParams: PoolParams)`;

return (
<>
<p>
Use <code>.registerPoolCertificate()</code> to register a pool
certificate:
</p>

<Codeblock data={code} isJson={false} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function RetirePoolCertificate() {
return (
<Section
sidebarTo="retirePoolCertificate"
header="Retire Pool Certificate"
contentFn={Content()}
/>
);
}

function Content() {
let code = `mesh
.retirePoolCertificate(poolId: string, epoch: number)`;

return (
<>
<p>
Use <code>.retirePoolCertificate()</code> to retire a pool certificate:
</p>

<Codeblock data={code} isJson={false} />
</>
);
}
35 changes: 18 additions & 17 deletions packages/demo/components/pages/apis/transaction/builder/schemas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ export default function Schemas() {
}

function Content() {
let codeMeshTxBuilderBody = ``;
codeMeshTxBuilderBody += `MeshTxBuilderBody = {\n`;
codeMeshTxBuilderBody += ` inputs: TxIn[]\n`;
codeMeshTxBuilderBody += ` outputs: Output[];\n`;
codeMeshTxBuilderBody += ` collaterals: PubKeyTxIn[];\n`;
codeMeshTxBuilderBody += ` requiredSignatures: string[];\n`;
codeMeshTxBuilderBody += ` referenceInputs: RefTxIn[];\n`;
codeMeshTxBuilderBody += ` mints: MintItem[];\n`;
codeMeshTxBuilderBody += ` changeAddress: string;\n`;
codeMeshTxBuilderBody += ` metadata: Metadata[];\n`;
codeMeshTxBuilderBody += ` validityRange: ValidityRange;\n`;
codeMeshTxBuilderBody += ` signingKey: string[];\n`;
codeMeshTxBuilderBody += `}\n`;

let codeInput = ``;
codeInput += `TxIn = PubKeyTxIn | ScriptTxIn;\n`;
let codeMeshTxBuilderBody = `MeshTxBuilderBody = {
inputs: TxIn[];
outputs: Output[];
extraInputs: UTxO[];
selectionThreshold: number;
collaterals: PubKeyTxIn[];
requiredSignatures: string[];
referenceInputs: RefTxIn[];
mints: MintItem[];
changeAddress: string;
metadata: Metadata[];
validityRange: ValidityRange;
certificates: Certificate[];
signingKey: string[];
}`;

let codeInput = `TxIn = PubKeyTxIn | ScriptTxIn;`;

let codePubKeyTxIn = `PubKeyTxIn = {
type: 'PubKey';
Expand Down Expand Up @@ -97,7 +98,7 @@ function Content() {
type: 'Plutus' | 'Native';
policyId: string;
assetName: string;
amount: number;
amount: string;
redeemer?: Redeemer;
scriptSource?:
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Content() {
.txInRedeemerValue(mConStr0([]))
.txInScript(getScriptCbor("Spending"))
.mintPlutusScriptV2()
.mint(1, policyId, tokenName)
.mint("1", policyId, tokenName)
.mintingScript(mintingScript)
.mintRedeemerValue(mConStr0([]))
.txOut(this.constants.walletAddress, [{ unit: policyId + tokenName, quantity: "1" }])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Content() {
const codeSnippet = `await mesh
.txIn(txInHash, txInId)
.mintPlutusScriptV2()
.mint(1, policyId, tokenName)
.mint("1", policyId, tokenName)
.mintingScript(mintingScript)
.mintRedeemerValue(mConStr0([]))
.txOut(this.constants.walletAddress, [{ unit: policyId + tokenName, quantity: "1" }])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Section from '../../../../common/section';
import Codeblock from '../../../../ui/codeblock';

export default function Staking() {
return (
<Section
sidebarTo="staking"
header="Build a transaction to (register stake certificate and) delegate stake to a pool"
contentFn={Content()}
/>
);
}

function Content() {
const codeSnippet = `const usedAddress = await wallet.getUnusedAddresses();
const { stakeCredential } = serializeBech32Address(usedAddress[0]);
await mesh
.txIn(txInHash, txInId)
.registerStakeCertificate(stakeCredential) // Skip this line if you are not staking for the first time
.delegateStakeCertificate(
stakeCredential,
'poolxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)
.changeAddress(changeAddress)
.complete();
const signedTx = mesh.completeSigning()`;

return (
<>
<p>
The following shows a simple example of building a transaction to
(register stake certificate and) delegate stake to a pool for the first
time.
</p>
<Codeblock data={codeSnippet} isJson={false} />
</>
);
}
36 changes: 30 additions & 6 deletions packages/demo/pages/apis/transaction/builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import CommonLayout from '../../../components/common/layout';
import InvalidInterval from '../../../components/pages/apis/transaction/builder/InvalidInterval';
import ChangeAddress from '../../../components/pages/apis/transaction/builder/changeAddress';
import Complete from '../../../components/pages/apis/transaction/builder/complete';
import Schemas from '../../../components/pages/apis/transaction/builder/schemas';
import MetadataValue from '../../../components/pages/apis/transaction/builder/metadataValue';
import MintPlutus from '../../../components/pages/apis/transaction/builder/mintPlutus';
import MintNative from '../../../components/pages/apis/transaction/builder/mintNative';
Expand All @@ -18,6 +17,11 @@ import TxInCollateral from '../../../components/pages/apis/transaction/builder/t
import TxOut from '../../../components/pages/apis/transaction/builder/txOut';
import CommonHero from '../../../components/pages/apis/transaction/commonHero';
import Metatags from '../../../components/site/metatags';
import RegisterCertificate from '../../../components/pages/apis/transaction/builder/registerCertificate';
import DeregisterCertificate from '../../../components/pages/apis/transaction/builder/deregisterCertificate';
import DelegateStakeCertificate from '../../../components/pages/apis/transaction/builder/delegateStakeCertificate';
import RegisterPoolCertificate from '../../../components/pages/apis/transaction/builder/registerPoolCertificate';
import RetirePoolCertificate from '../../../components/pages/apis/transaction/builder/retirePoolCertificate';

const TransactionBuilderPage: NextPage = () => {
const sidebarItems = [
Expand Down Expand Up @@ -56,6 +60,26 @@ const TransactionBuilderPage: NextPage = () => {
label: 'Add metadata',
to: 'metadataValue',
},
{
label: 'Register Stake Certificate',
to: 'registerCertificate',
},
{
label: 'Deregister Stake Certificate',
to: 'deregisterCertificate',
},
{
label: 'Delegate Stake',
to: 'delegateStakeCertificate',
},
{
label: 'Register Pool Certificate',
to: 'registerPoolCertificate',
},
{
label: 'Retire Pool Certificate',
to: 'retirePoolCertificate',
},
{
label: 'Sign with signing key',
to: 'signingKey',
Expand All @@ -64,10 +88,6 @@ const TransactionBuilderPage: NextPage = () => {
label: 'Complete transaction building',
to: 'complete',
},
{
label: 'Schemas',
to: 'schemas',
},
];

return (
Expand Down Expand Up @@ -101,9 +121,13 @@ const TransactionBuilderPage: NextPage = () => {
<ChangeAddress />
<InvalidInterval />
<MetadataValue />
<RegisterCertificate />
<DeregisterCertificate />
<DelegateStakeCertificate />
<RegisterPoolCertificate />
<RetirePoolCertificate />
<SigningKey />
<Complete />
<Schemas />
</CommonLayout>
</>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/demo/pages/apis/transaction/builderExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Metatags from '../../../components/site/metatags';
import LockFund from '../../../components/pages/apis/transaction/builderExample/lockFund';
import UnlockFund from '../../../components/pages/apis/transaction/builderExample/unlockFund';
import MintToken from '../../../components/pages/apis/transaction/builderExample/mintToken';
import Staking from '../../../components/pages/apis/transaction/builderExample/staking';

const TransactionBuilderExamplePage: NextPage = () => {
const sidebarItems = [
Expand All @@ -20,6 +21,7 @@ const TransactionBuilderExamplePage: NextPage = () => {
{ label: 'Lock Fund', to: 'lockFund' },
{ label: 'Unlock Fund', to: 'unlockFund' },
{ label: 'Mint Tokens', to: 'mintToken' },
{ label: 'Delegate Stake', to: 'staking' },
{ label: 'Complex Transaction', to: 'complexTransaction' },
{ label: 'Build without dependency', to: 'withoutDependency' },
{ label: 'Build with object', to: 'withObject' },
Expand Down Expand Up @@ -50,6 +52,7 @@ const TransactionBuilderExamplePage: NextPage = () => {
<LockFund />
<UnlockFund />
<MintToken />
<Staking />
<ComplexTransaction />
<TransactionWithoutDependency />
<TransactionWithObject />
Expand Down
Loading

0 comments on commit 8179001

Please sign in to comment.