mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-01-18 15:36:27 +00:00
deploy license finished
This commit is contained in:
parent
b87cc10c3d
commit
61a74636d1
@ -3,6 +3,7 @@ import { LicenseService } from './license.service';
|
|||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
DeployLicenseDto,
|
DeployLicenseDto,
|
||||||
|
GetLicenseInfoDto,
|
||||||
GetShareLicense,
|
GetShareLicense,
|
||||||
RequestLicenseDto,
|
RequestLicenseDto,
|
||||||
} from './license.dto';
|
} from './license.dto';
|
||||||
@ -10,7 +11,7 @@ import {
|
|||||||
@Controller('license')
|
@Controller('license')
|
||||||
export class LicenseController {
|
export class LicenseController {
|
||||||
constructor(private readonly licenseService: LicenseService) {}
|
constructor(private readonly licenseService: LicenseService) {}
|
||||||
@Get('request')
|
@Post('request')
|
||||||
async getLicenseRequest(@Body() dto: RequestLicenseDto) {
|
async getLicenseRequest(@Body() dto: RequestLicenseDto) {
|
||||||
return this.licenseService.request(dto);
|
return this.licenseService.request(dto);
|
||||||
}
|
}
|
||||||
@ -21,7 +22,7 @@ export class LicenseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('total-payout')
|
@Get('total-payout')
|
||||||
async getLicenseResponse(@Body() dto: RequestLicenseDto) {
|
async getLicenseResponse(@Body() dto: GetLicenseInfoDto) {
|
||||||
return this.licenseService.getTotalPayoutInUSD(dto);
|
return this.licenseService.getTotalPayoutInUSD(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ export class LicenseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('owners')
|
@Get('owners')
|
||||||
async getOwners(@Body() dto: GetShareLicense) {
|
async getOwners(@Body() dto: GetLicenseInfoDto) {
|
||||||
return this.licenseService.getOwners(dto);
|
return this.licenseService.getOwners(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,5 +33,6 @@ export class GetLicenseResponseDto extends GetLicenseInfoDto {}
|
|||||||
|
|
||||||
export class GetShareLicense extends GetLicenseInfoDto {
|
export class GetShareLicense extends GetLicenseInfoDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ApiProperty()
|
||||||
ownerAddress: string;
|
ownerAddress: string;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ export class LicenseService extends BaseContractService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTotalPayoutInUSD(dto: GetLicenseResponseDto) {
|
async getTotalPayoutInUSD(dto: GetLicenseInfoDto) {
|
||||||
const { contractAddress } = dto;
|
const { contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
const { abi } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
@ -44,7 +44,7 @@ export class LicenseService extends BaseContractService {
|
|||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const answer: bigint = await contract.totalPayoutInUSD();
|
const answer: bigint = await contract.request();
|
||||||
console.log('=>(license.service.ts:45) answer', answer);
|
console.log('=>(license.service.ts:45) answer', answer);
|
||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
@ -57,9 +57,20 @@ export class LicenseService extends BaseContractService {
|
|||||||
);
|
);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner();
|
||||||
|
|
||||||
const licenseContract = new ethers.ContractFactory(abi, bytecode, signer);
|
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
||||||
|
|
||||||
const myContract = await licenseContract.getDeployTransaction(
|
const abiEncodedConstructorArguments = abiCoder.encode(
|
||||||
|
[
|
||||||
|
'address',
|
||||||
|
'address',
|
||||||
|
'string',
|
||||||
|
'uint',
|
||||||
|
'address',
|
||||||
|
'address[]',
|
||||||
|
'uint[]',
|
||||||
|
'address',
|
||||||
|
],
|
||||||
|
[
|
||||||
CHAINLINK.AMOY.CHAINLINK_TOKEN,
|
CHAINLINK.AMOY.CHAINLINK_TOKEN,
|
||||||
CHAINLINK.AMOY.ORACLE_ADDRESS,
|
CHAINLINK.AMOY.ORACLE_ADDRESS,
|
||||||
CHAINLINK.AMOY.JOB_IDS.UINT,
|
CHAINLINK.AMOY.JOB_IDS.UINT,
|
||||||
@ -68,12 +79,14 @@ export class LicenseService extends BaseContractService {
|
|||||||
owners,
|
owners,
|
||||||
shares,
|
shares,
|
||||||
payrollAddress,
|
payrollAddress,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
const fullBytecode = bytecode + abiEncodedConstructorArguments.substring(2);
|
||||||
const submitData = await this.multiSigService.submitTransaction({
|
const submitData = await this.multiSigService.submitTransaction({
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: null,
|
destination: null,
|
||||||
value: '0',
|
value: '0',
|
||||||
data: myContract.data,
|
data: fullBytecode,
|
||||||
});
|
});
|
||||||
delete submitData.data;
|
delete submitData.data;
|
||||||
return submitData;
|
return submitData;
|
||||||
@ -102,9 +115,20 @@ export class LicenseService extends BaseContractService {
|
|||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const answer: string[] = await contract.owners();
|
const owners: string[] = [];
|
||||||
|
|
||||||
return answer;
|
for (let i = 0; i < 10; i++) {
|
||||||
|
try {
|
||||||
|
const owner = await contract.owners(i);
|
||||||
|
owners.push(owner);
|
||||||
|
} catch (e) {
|
||||||
|
// this.logger.error(e);
|
||||||
|
console.log('OWNERS LIMIT');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return owners;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShares(dto: GetShareLicense) {
|
async getShares(dto: GetShareLicense) {
|
||||||
@ -117,20 +141,7 @@ export class LicenseService extends BaseContractService {
|
|||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const answer: number = await contract.getShare(ownerAddress);
|
const answer: number = await contract.getShare(ownerAddress);
|
||||||
|
console.log('=>(license.service.ts:135) answer', answer);
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getTotalPayout(dto: GetLicenseInfoDto) {
|
|
||||||
const { contractAddress } = dto;
|
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
|
||||||
'StreamingRightsManagement',
|
|
||||||
);
|
|
||||||
const signer = await this.providerService.getSigner();
|
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
|
||||||
|
|
||||||
const answer: number = await contract.totalPayoutInUSD();
|
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
@ -92,23 +92,34 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner();
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
const deployedAddress = await this.calculateFutureAddress(contractAddress);
|
|
||||||
|
|
||||||
|
const input = dto.index + new Date().getTime().toString();
|
||||||
|
const hashed = ethers.keccak256(ethers.toUtf8Bytes(input));
|
||||||
|
const salt = BigInt(hashed.substring(0, 10));
|
||||||
|
|
||||||
|
if (isDeploy) {
|
||||||
|
const tx = await contract.executeDeployTransaction(index, salt);
|
||||||
|
|
||||||
|
const txResponse: TransactionReceipt = await tx.wait();
|
||||||
|
const eventParse = parseLogs(txResponse, contract, 'ExecuteTransaction');
|
||||||
|
const deployedParse = parseLogs(txResponse, contract, 'ContractDeployed');
|
||||||
|
return {
|
||||||
|
txHash: txResponse.hash,
|
||||||
|
sender: eventParse.args[0].toString(),
|
||||||
|
txIndex: eventParse.args[1].toString(),
|
||||||
|
deployedAddress: deployedParse.args[0].toString(),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
const tx = await contract.executeTransaction(index);
|
const tx = await contract.executeTransaction(index);
|
||||||
|
|
||||||
const txResponse: TransactionReceipt = await tx.wait();
|
const txResponse: TransactionReceipt = await tx.wait();
|
||||||
console.log('=>(multi-sig.service.ts:101) txResponse', txResponse.logs);
|
|
||||||
|
|
||||||
const eventParse = parseLogs(txResponse, contract, 'ExecuteTransaction');
|
const eventParse = parseLogs(txResponse, contract, 'ExecuteTransaction');
|
||||||
const data = {
|
return {
|
||||||
txHash: txResponse.hash,
|
txHash: txResponse.hash,
|
||||||
sender: eventParse.args[0].toString(),
|
sender: eventParse.args[0].toString(),
|
||||||
txIndex: eventParse.args[1].toString(),
|
txIndex: eventParse.args[1].toString(),
|
||||||
};
|
};
|
||||||
if (isDeploy) {
|
|
||||||
return { ...data, deployedAddress };
|
|
||||||
} else {
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +130,7 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
|
|
||||||
return getContractAddress({
|
return getContractAddress({
|
||||||
from: contractAddress,
|
from: contractAddress,
|
||||||
nonce: nonce + 1,
|
nonce: nonce,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
|||||||
console.log('🚀 ~ AllExceptionsFilter ~ exception:', exception);
|
console.log('🚀 ~ AllExceptionsFilter ~ exception:', exception);
|
||||||
const ctx = host.switchToHttp();
|
const ctx = host.switchToHttp();
|
||||||
const response = ctx.getResponse<Response>();
|
const response = ctx.getResponse<Response>();
|
||||||
const request = ctx.getRequest<Request>();
|
|
||||||
const httpStatus =
|
const httpStatus =
|
||||||
exception instanceof HttpException
|
exception instanceof HttpException
|
||||||
? exception.getStatus()
|
? exception.getStatus()
|
||||||
|
@ -68,13 +68,13 @@ contract StreamingRightsManagement is ChainlinkClient, ConfirmedOwner {
|
|||||||
//update share
|
//update share
|
||||||
//change payout address
|
//change payout address
|
||||||
//
|
//
|
||||||
function getShare(address owner) public returns(uint){
|
function getShare(address owner) public view returns(uint){
|
||||||
return ownerShare[owner];
|
return ownerShare[owner];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send a request to the Chainlink oracle
|
// Send a request to the Chainlink oracle
|
||||||
function request() public {
|
function request() external onlyOwner{
|
||||||
|
|
||||||
Chainlink.Request memory req = _buildOperatorRequest(jobId, this.fulfill.selector);
|
Chainlink.Request memory req = _buildOperatorRequest(jobId, this.fulfill.selector);
|
||||||
|
|
||||||
|
@ -132,14 +132,6 @@ contract MultiSigWallet {
|
|||||||
if (success) {
|
if (success) {
|
||||||
transaction.executed = true;
|
transaction.executed = true;
|
||||||
emit ExecuteTransaction(msg.sender, _txIndex, transaction.to);
|
emit ExecuteTransaction(msg.sender, _txIndex, transaction.to);
|
||||||
if (returnData.length > 0) {
|
|
||||||
address deployedContractAddress;
|
|
||||||
assembly {
|
|
||||||
deployedContractAddress := mload(add(returnData, 20))
|
|
||||||
}
|
|
||||||
// You can emit an event with the address of the deployed contract
|
|
||||||
emit ContractDeployed(deployedContractAddress);
|
|
||||||
}
|
|
||||||
removeTransaction(_txIndex);
|
removeTransaction(_txIndex);
|
||||||
} else {
|
} else {
|
||||||
// Get the revert reason and emit it
|
// Get the revert reason and emit it
|
||||||
@ -156,6 +148,39 @@ contract MultiSigWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function executeDeployTransaction(uint _txIndex, uint256 _salt) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
||||||
|
Transaction storage transaction = transactions[_txIndex];
|
||||||
|
require(
|
||||||
|
transaction.numConfirmations >= numConfirmationsRequired,
|
||||||
|
"cannot execute tx"
|
||||||
|
);
|
||||||
|
|
||||||
|
address deployedAddress;
|
||||||
|
|
||||||
|
bytes memory bytecode = transaction.data;
|
||||||
|
|
||||||
|
// Assembly to deploy contract using CREATE2
|
||||||
|
assembly {
|
||||||
|
deployedAddress :=
|
||||||
|
create2(
|
||||||
|
callvalue(), // wei sent with current call
|
||||||
|
// Actual code starts after skipping the first 32 bytes
|
||||||
|
add(bytecode, 0x20),
|
||||||
|
mload(bytecode), // Load the size of code contained in the first 32 bytes
|
||||||
|
_salt // Salt from function arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
if iszero(extcodesize(deployedAddress)) { revert(0, 0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
require(deployedAddress != address(0), "Failed to deploy contract");
|
||||||
|
transaction.executed = true;
|
||||||
|
emit ExecuteTransaction(msg.sender, _txIndex, deployedAddress);
|
||||||
|
emit ContractDeployed(deployedAddress);
|
||||||
|
removeTransaction(_txIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function revokeConfirmation(
|
function revokeConfirmation(
|
||||||
uint _txIndex
|
uint _txIndex
|
||||||
) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user