diff --git a/mock/resource.js b/mock/resource.js index 82c6887..eba6b1c 100644 --- a/mock/resource.js +++ b/mock/resource.js @@ -15,7 +15,7 @@ module.exports = [{ id: '@id', path: config.query.path ? config.query.path + '.@word(3,5)' : '@pick([\'payment\',\'load\',\'resource\']).@pick([\'bcos\',\'bcos_gm\',\'fabric\']).@word(3,5)', checksum: 'checksum', - 'stubType|1': ['BCOS2.0', 'GM_BCOS2.0', 'Fabric1.4'], + 'stubType|1': ['BCOS2.0', 'GM_BCOS2.0', 'Fabric1.4', 'BCOS3_ECDSA_EVM', 'BCOS3_GM_EVM'], properties: '@sentence(3,3)', distance: '@integer(0, 3)' }] diff --git a/src/utils/resource.js b/src/utils/resource.js index f39f3ad..dad4d93 100644 --- a/src/utils/resource.js +++ b/src/utils/resource.js @@ -22,6 +22,17 @@ export function buildBCOSDeployRequest(formData) { } } +export function buildBCOSDeployWasmRequest(formData) { + return { + version: 1, + path: formData.fullPath || formData.prependPath + formData.appendPath, + data: { + command: formData.method, + args: [formData.appendPath || formData.fullPath.split('.')[2], formData.abiContent, formData.sourceContent] + } + } +} + export function buildBCOSRegisterRequest(formData) { return { version: 1, diff --git a/src/views/resource/resourceDeployment.vue b/src/views/resource/resourceDeployment.vue index 916b901..3ca5e4d 100644 --- a/src/views/resource/resourceDeployment.vue +++ b/src/views/resource/resourceDeployment.vue @@ -21,8 +21,10 @@ - - + + + + @@ -32,7 +34,7 @@ @@ -40,7 +42,7 @@ Deploy @@ -82,8 +84,11 @@ - - + + + + + + + 只能上传Liquid合约编译后的WASM文件和ABI文件 + + 选取文件 + + + import { buildBCOSDeployRequest, + buildBCOSDeployWasmRequest, buildBCOSRegisterRequest, buildFabricInstallRequest, buildFabricInstantiateRequest, buildFabricUpgradeRequest, clearForm @@ -281,7 +311,10 @@ export default { policy: 'default', args: null, chosenSolidity: null, + chosenWasm: null, + chosenAbi: null, sourceContent: null, + abiContent: null, compressedContent: null }, solidityFiles: [], @@ -438,9 +471,24 @@ export default { this.zipContractFilesMap = {} }, onBCOSDeploy() { + var isWASM = false + if (this.form.stubType !== null && this.form.stubType.includes('WASM')) { + isWASM = true + } try { - this.mergeSolidityFile('./' + this.form.chosenSolidity) - this.mergeSourceContractLineToString() + if (isWASM) { + if (this.form.sourceContent === null || this.form.abiContent === null) { + this.$alert('请同时增加二进制文件和ABI文件!', '错误', { + type: 'error' + }).catch(_ => { + }) + this.loading = false + return + } + } else { + this.mergeSolidityFile('./' + this.form.chosenSolidity) + this.mergeSourceContractLineToString() + } } catch (e) { this.loading = false return @@ -457,7 +505,7 @@ export default { confirmButtonText: '确认部署', cancelButtonText: '取消部署' }).then(_ => { - bcosDeploy(buildBCOSDeployRequest(this.form)).then(response => { + bcosDeploy(isWASM ? buildBCOSDeployWasmRequest(this.form) : buildBCOSDeployRequest(this.form)).then(response => { this.loading = false if (response.errorCode !== 0) { handleErrorMsgBox( @@ -696,6 +744,25 @@ export default { this.form.chosenSolidity = null this.$refs.uploadContract.submit() }, + changeWasmContractFile(file, fileList) { + if (fileList.length === 3) { + fileList.shift() + } + console.log(file) + const fileReader = new FileReader() + if (file !== null && /(wasm$)/.test(file.raw.type)) { + fileReader.onload = async(e) => { + this.form.sourceContent = Array.prototype.map.call(new Uint8Array(e.target.result), x => (x.toString(16).padStart(2, '0'))).join('') + } + fileReader.readAsArrayBuffer(file.raw) + } else if (file !== null && /(.abi$)/.test(file.raw.name)) { + fileReader.onload = async(e) => { + this.form.abiContent = e.target.result + } + fileReader.readAsText(file.raw) + } + this.$refs.uploadContract.submit() + }, changeChaincodeFile(file, fileList) { if (fileList.length === 2) { fileList.shift() @@ -802,6 +869,21 @@ export default { params.onError() } }, + uploadWasmContractHandler(params) { + if ((this.form.stubType === 'BCOS3_GM_WASM' || this.form.stubType === 'BCOS3_ECDSA_WASM')) { + if (params.file !== null && /(wasm$)/.test(params.file.type)) { + this.form.chosenWasm = params.file.name + } else if (params.file !== null && /(.abi$)/.test(params.file.name)) { + this.form.chosenAbi = params.file.name + } else { + this.$alert('请选择WASM或者ABI文件!', '错误', { + type: 'error' + }).catch(_ => {}) + params.onProgress({ percent: 0 }) + params.onError() + } + } + }, async readBaseBytes(params) { const readFile = new FileReader() readFile.readAsDataURL(params.file)