feat: deploy bundled (#267)
This commit is contained in:
@@ -39,10 +39,13 @@ export interface FromSrcTxContractData extends CommonContractData {
|
||||
|
||||
export interface ContractDeploy {
|
||||
contractTxId: string;
|
||||
srcTxId: string;
|
||||
srcTxId?: string;
|
||||
}
|
||||
|
||||
export interface CreateContract {
|
||||
deploy(contractData: ContractData, disableBundling?: boolean): Promise<ContractDeploy>;
|
||||
|
||||
deployFromSourceTx(contractData: FromSrcTxContractData, disableBundling?: boolean): Promise<ContractDeploy>;
|
||||
|
||||
deployBundled(rawDataItem: Buffer): Promise<ContractDeploy>;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { WARP_GW_URL } from '../../../core/WarpFactory';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
import { CreateContract, ContractData, ContractDeploy, FromSrcTxContractData } from '../CreateContract';
|
||||
import { SourceImpl } from './SourceImpl';
|
||||
import { Buffer } from 'redstone-isomorphic';
|
||||
|
||||
export class DefaultCreateContract implements CreateContract {
|
||||
private readonly logger = LoggerFactory.INST.create('DefaultCreateContract');
|
||||
@@ -107,6 +108,31 @@ export class DefaultCreateContract implements CreateContract {
|
||||
}
|
||||
}
|
||||
|
||||
async deployBundled(rawDataItem: Buffer): Promise<ContractDeploy> {
|
||||
const response = await fetch(`${WARP_GW_URL}/gateway/contracts/deploy-bundled`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
Accept: 'application/json'
|
||||
},
|
||||
body: rawDataItem
|
||||
});
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
if (typeof response.json === 'function') {
|
||||
response.json().then((responseError) => {
|
||||
if (responseError.message) {
|
||||
this.logger.error(responseError.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
throw new Error(
|
||||
`Error while deploying data item. Warp Gateway responded with status ${response.status} ${response.statusText}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async post(contractTx: Transaction, srcTx: Transaction = null): Promise<any> {
|
||||
let body: any = {
|
||||
contractTx
|
||||
|
||||
Reference in New Issue
Block a user