-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: init serializers and deserializers
- Loading branch information
1 parent
0d5e604
commit 5a9854e
Showing
5 changed files
with
121 additions
and
72 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
apps/playground/src/pages/apis/utilities/deserializers/deserialize-address.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState } from "react"; | ||
|
||
import { deserializeAddress } from "@meshsdk/core"; | ||
|
||
import Input from "~/components/form/input"; | ||
import InputTable from "~/components/sections/input-table"; | ||
import LiveCodeDemo from "~/components/sections/live-code-demo"; | ||
import TwoColumnsScroll from "~/components/sections/two-columns-scroll"; | ||
import { demoAddresses } from "~/data/cardano"; | ||
|
||
export default function DeserializeAddress() { | ||
return ( | ||
<TwoColumnsScroll | ||
sidebarTo="deserializeAddress" | ||
title="Deserialize Address" | ||
leftSection={Left()} | ||
rightSection={Right()} | ||
/> | ||
); | ||
} | ||
|
||
function Left() { | ||
return ( | ||
<> | ||
<p> | ||
Deserialize bech32 address into payment and staking parts, with | ||
visibility of whether they are script or key hash. | ||
</p> | ||
</> | ||
); | ||
} | ||
|
||
function Right() { | ||
const [userInput, setUserInput] = useState<string>( | ||
demoAddresses.testnetPayment, | ||
); | ||
|
||
async function runDemo() { | ||
return deserializeAddress(userInput); | ||
} | ||
|
||
let codeSnippet = `deserializeAddress('${userInput}');`; | ||
|
||
return ( | ||
<LiveCodeDemo | ||
title="Deserialize Address" | ||
subtitle="Convert bech32 address to The deserialized address object" | ||
code={codeSnippet} | ||
runCodeFunction={runDemo} | ||
> | ||
<InputTable | ||
listInputs={[ | ||
<Input | ||
value={userInput} | ||
onChange={(e) => setUserInput(e.target.value)} | ||
label="Address" | ||
key={0} | ||
/>, | ||
]} | ||
/> | ||
</LiveCodeDemo> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
apps/playground/src/pages/apis/utilities/deserializers/resolve-data-hash.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/playground/src/pages/apis/utilities/serializers/serialize-plutus-script.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PlutusScript, serializePlutusScript } from "@meshsdk/core"; | ||
|
||
import LiveCodeDemo from "~/components/sections/live-code-demo"; | ||
import TwoColumnsScroll from "~/components/sections/two-columns-scroll"; | ||
import { demoPlutusAlwaysSucceedScript } from "~/data/cardano"; | ||
|
||
export default function SerializePlutusScript() { | ||
return ( | ||
<TwoColumnsScroll | ||
sidebarTo="serializePlutusScript" | ||
title="Serialize Plutus Script" | ||
leftSection={Left()} | ||
rightSection={Right()} | ||
/> | ||
); | ||
} | ||
|
||
function Left() { | ||
return ( | ||
<> | ||
<p>Serialize Plutus script into bech32 address.</p> | ||
</> | ||
); | ||
} | ||
|
||
function Right() { | ||
async function runDemo() { | ||
const script: PlutusScript = { | ||
code: demoPlutusAlwaysSucceedScript, | ||
version: "V2", | ||
}; | ||
|
||
const address = serializePlutusScript(script); | ||
|
||
return address; | ||
} | ||
|
||
let codeSnippet = ``; | ||
|
||
return ( | ||
<LiveCodeDemo | ||
title="Serialize Plutus Script" | ||
subtitle="Serialize Plutus script into bech32 address" | ||
code={codeSnippet} | ||
runCodeFunction={runDemo} | ||
></LiveCodeDemo> | ||
); | ||
} |