Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to deriveFromChain given a module reference when initializing a contract instance #154

7 changes: 5 additions & 2 deletions front-end-tools/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import {
} from '@concordium/react-components';

import { Alert } from 'react-bootstrap';
import { ModuleReference } from '@concordium/web-sdk';
import DeployComponent from './components/DeployComponent';
import ReadComponent from './components/ReadComponent';
import UpdateComponent from './components/UpdateComponent';
@@ -48,8 +49,10 @@ export default function Main(props: ConnectionProps) {
const [accountBalance, setAccountBalance] = useState<string | undefined>(undefined);

// Shared state between deploy step and init step
const [moduleReferenceCalculated, setModuleReferenceCalculated] = useState<string | undefined>(undefined);
const [moduleReferenceDeployed, setModuleReferenceDeployed] = useState<string | undefined>(undefined);
const [moduleReferenceCalculated, setModuleReferenceCalculated] = useState<ModuleReference.Type | undefined>(
undefined
);
const [moduleReferenceDeployed, setModuleReferenceDeployed] = useState<ModuleReference.Type | undefined>(undefined);
const [contracts, setContracts] = useState<string[]>([]);
const [embeddedModuleSchemaBase64Init, setEmbeddedModuleSchemaBase64Init] = useState<string | undefined>(undefined);

18 changes: 11 additions & 7 deletions front-end-tools/src/components/DeployComponent.tsx
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@ interface ConnectionProps {
isTestnet: boolean;
setContracts: (contracts: string[]) => void;
setEmbeddedModuleSchemaBase64Init: (embeddedModuleSchemaBase64Init: string) => void;
setModuleReferenceDeployed: (moduleReferenceDeployed: string | undefined) => void;
setModuleReferenceCalculated: (moduleReferenceCalculated: string) => void;
moduleReferenceCalculated: string | undefined;
setModuleReferenceDeployed: (moduleReferenceDeployed: ModuleReference.Type | undefined) => void;
setModuleReferenceCalculated: (moduleReferenceCalculated: ModuleReference.Type) => void;
moduleReferenceCalculated: ModuleReference.Type | undefined;
}

/**
@@ -76,7 +76,9 @@ export default function DeployComponenet(props: ConnectionProps) {
report.outcome.summary.transactionType === TransactionKindString.DeployModule
) {
setTransactionOutcome('Success');
setModuleReferenceDeployed(report.outcome.summary.moduleDeployed.contents);
setModuleReferenceDeployed(
ModuleReference.fromHexString(report.outcome.summary.moduleDeployed.contents)
);
clearInterval(interval);
} else {
setTransactionOutcome('Fail');
@@ -97,7 +99,7 @@ export default function DeployComponenet(props: ConnectionProps) {
useEffect(() => {
if (connection && client && moduleReferenceCalculated) {
client
.getModuleSource(ModuleReference.fromHexString(moduleReferenceCalculated))
.getModuleSource(moduleReferenceCalculated)
.then((value) => {
if (value === undefined) {
setIsModuleReferenceAlreadyDeployedStep1(false);
@@ -160,7 +162,9 @@ export default function DeployComponenet(props: ConnectionProps) {

setBase64Module(module);
setModuleReferenceCalculated(
Buffer.from(sha256([new Uint8Array(arrayBuffer)])).toString('hex')
ModuleReference.fromBuffer(
Buffer.from(sha256([new Uint8Array(arrayBuffer)]))
)
);

// Concordium's tooling create versioned modules e.g. `.wasm.v1` now.
@@ -250,7 +254,7 @@ export default function DeployComponenet(props: ConnectionProps) {
<>
<div className="actionResultBox">
Calculated module reference:
<div>{moduleReferenceCalculated}</div>
<div>{moduleReferenceCalculated.moduleRef}</div>
</div>
<div className="actionResultBox">
Module in base64:
Loading