Skip to content

Commit

Permalink
[sui] add walrus upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kairoski03 committed Nov 14, 2024
1 parent 6ad577b commit 30db95c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/components/sui/Compiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
const [targetFunc, setTargetFunc] = useState<SuiFunc>();
const [genericParameters, setGenericParameters] = useState<string[]>([]);
const [parameters, setParameters] = useState<any[]>([]);
const [zipBlob, setZipBlob] = useState<Blob | undefined>(undefined);

const [uploadCodeChecked, setUploadCodeChecked] = useState(true);
useEffect(() => {
Expand All @@ -165,6 +166,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
setFileNames([]);
setCompiledModulesAndDeps(undefined);
setCliVersion('');
setZipBlob(undefined);
}, [compileTarget]);

const handleCheckboxChange = (event: {
Expand Down Expand Up @@ -195,6 +197,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
setFileNames([]);
setCompiledModulesAndDeps(undefined);
setCliVersion('');
setZipBlob(undefined);
} catch (e) {
log.info(`no out folder`);
}
Expand Down Expand Up @@ -285,6 +288,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
const address = accountID;
const timestamp = Date.now().toString();
setCompileTimestamp(timestamp);
setZipBlob(blob);

// ------------------------------------------------------------------
const isSrcZipUploadSuccess = await FileUtil.uploadSrcZip({
Expand Down Expand Up @@ -1207,6 +1211,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
setFileNames([]);
setCompiledModulesAndDeps(undefined);
setCliVersion('');
setZipBlob(undefined);

if (isEmptyList(artifactPaths)) {
return [];
Expand Down Expand Up @@ -1415,6 +1420,7 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
setInputAddress={setInputAddress}
initContract={initContract}
uploadCodeChecked={uploadCodeChecked}
blob={zipBlob}
/>
) : null
// <p className="text-center" style={{ marginTop: '0px !important', marginBottom: '3px' }}>
Expand Down
65 changes: 48 additions & 17 deletions src/components/sui/Deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface InterfaceProps {
setInputAddress: Function;
initContract: Function;
uploadCodeChecked: boolean;
blob: Blob | undefined;
}

export const Deploy: React.FunctionComponent<InterfaceProps> = ({
Expand All @@ -67,6 +68,7 @@ export const Deploy: React.FunctionComponent<InterfaceProps> = ({
setInputAddress,
initContract,
uploadCodeChecked,
blob,
}) => {
const [inProgress, setInProgress] = useState<boolean>(false);
const [deployIconSpin, setDeployIconSpin] = useState<string>('');
Expand Down Expand Up @@ -209,23 +211,52 @@ export const Deploy: React.FunctionComponent<InterfaceProps> = ({
);
log.info(`sui-packages api res`, res);

axios
.post(COMPILER_API_ENDPOINT + '/sui/verifications', {
network: res.data.chainId,
packageId: res.data.packageId,
})
.then((response) => {
console.log('Success (POST /sui/verifications): ', response.data);
})
.catch((error) => {
console.error(
'Error (POST /sui/verifications):',
error.response ? error.response.data : error.message,
);
})
.finally(() => {
console.log('POST /sui/verifications Request completed');
});
if (uploadCodeChecked) {
axios
.post(COMPILER_API_ENDPOINT + '/sui/verifications', {
network: res.data.chainId,
packageId: res.data.packageId,
})
.then((response) => {
console.log('Success (POST /sui/verifications): ', response.data);
console.log(`@@@ blob`, blob);
if (blob) {
console.log(`try walrus upload.`);
axios
.post('https://publisher.walrus-testnet.walrus.space', blob, {
headers: {
'Content-Type': 'application/octet-stream',
},
})
.then((response) => {
console.log(
'Success (POST https://publisher.walrus-testnet.walrus.space): ',
response.data,
);
})
.catch((error) => {
console.error(
'Error (POST https://publisher.walrus-testnet.walrus.space):',
error.response ? error.response.data : error.message,
);
})
.finally(() => {
console.log(
'POST https://publisher.walrus-testnet.walrus.space): Request completed',
);
});
}
})
.catch((error) => {
console.error(
'Error (POST /sui/verifications):',
error.response ? error.response.data : error.message,
);
})
.finally(() => {
console.log('POST /sui/verifications Request completed');
});
}
} catch (e) {
log.error(`sui-packages api error`);
console.error(e);
Expand Down

0 comments on commit 30db95c

Please sign in to comment.