mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-01-18 15:36:27 +00:00
get header decorrator + dynamic seed
This commit is contained in:
parent
4d2e169795
commit
49a2687538
@ -4,5 +4,5 @@ import { ProviderService } from './provider/provider.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export abstract class BaseContractService {
|
export abstract class BaseContractService {
|
||||||
constructor(public readonly providerService: ProviderService) {}
|
constructor(public readonly providerService: ProviderService) {}
|
||||||
abstract deploy(dto: object): Promise<any>;
|
abstract deploy(dto: object, seed: string): Promise<any>;
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,10 @@ export class ProviderService {
|
|||||||
return this.provider;
|
return this.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSigner() {
|
async getSigner(seed: string) {
|
||||||
if (!this.provider) {
|
if (!this.provider) {
|
||||||
await this.getProvider();
|
await this.getProvider();
|
||||||
}
|
}
|
||||||
return new ethers.Wallet(
|
return ethers.Wallet.fromPhrase(seed, this.provider);
|
||||||
this.configService.getOrThrow('POLYGON_PK'),
|
|
||||||
this.provider,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
chain-api/src/common/common.dto.ts
Normal file
1
chain-api/src/common/common.dto.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import { IsString } from 'class-validator';
|
@ -6,24 +6,32 @@ import {
|
|||||||
RequestAgreementDto,
|
RequestAgreementDto,
|
||||||
} from './agreement.dto';
|
} from './agreement.dto';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { GetHeader } from '../../decorators/getHeader.decorator';
|
||||||
@ApiTags('Agreement')
|
@ApiTags('Agreement')
|
||||||
@Controller('agreements')
|
@Controller('agreements')
|
||||||
export class AgreementController {
|
export class AgreementController {
|
||||||
constructor(private readonly agreementService: AgreementService) {}
|
constructor(private readonly agreementService: AgreementService) {}
|
||||||
|
|
||||||
@Post('deploy')
|
@Post('deploy')
|
||||||
async deployAgreement(@Body() deployDto: DeployAgreementDto) {
|
async deployAgreement(
|
||||||
return await this.agreementService.deploy(deployDto);
|
@Body() deployDto: DeployAgreementDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return await this.agreementService.deploy(deployDto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':contractAddress')
|
@Get(':contractAddress')
|
||||||
async getAgreementResponse(
|
async getAgreementResponse(
|
||||||
@Param('contractAddress') contractAddress: string,
|
@Param('contractAddress') contractAddress: string,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
) {
|
) {
|
||||||
return await this.agreementService.getResponse({ contractAddress });
|
return await this.agreementService.getResponse({ contractAddress }, seed);
|
||||||
}
|
}
|
||||||
@Post('request')
|
@Post('request')
|
||||||
async requestAgreement(@Body() requestDto: RequestAgreementDto) {
|
async requestAgreement(
|
||||||
return await this.agreementService.request(requestDto);
|
@Body() requestDto: RequestAgreementDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return await this.agreementService.request(requestDto, seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export class AgreementService extends BaseContractService {
|
|||||||
) {
|
) {
|
||||||
super(providerService);
|
super(providerService);
|
||||||
}
|
}
|
||||||
async deploy(dto: DeployAgreementDto): Promise<any> {
|
async deploy(dto: DeployAgreementDto, seed: string): Promise<any> {
|
||||||
const { multiSigWallet } = dto;
|
const { multiSigWallet } = dto;
|
||||||
const { bytecode } = await hre.artifacts.readArtifact('Agreement');
|
const { bytecode } = await hre.artifacts.readArtifact('Agreement');
|
||||||
|
|
||||||
@ -36,20 +36,23 @@ export class AgreementService extends BaseContractService {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
const fullBytecode = bytecode + abiEncodedConstructorArguments.substring(2);
|
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: fullBytecode,
|
data: fullBytecode,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
delete submitData.data;
|
delete submitData.data;
|
||||||
return submitData;
|
return submitData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getResponse(dto: GetAgreementInfoDto) {
|
async getResponse(dto: GetAgreementInfoDto, seed: string) {
|
||||||
const { contractAddress } = dto;
|
const { contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('Agreement');
|
const { abi } = await hre.artifacts.readArtifact('Agreement');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -57,7 +60,7 @@ export class AgreementService extends BaseContractService {
|
|||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(dto: RequestAgreementDto) {
|
async request(dto: RequestAgreementDto, seed: string) {
|
||||||
const { multiSigWallet, contractAddress, url } = dto;
|
const { multiSigWallet, contractAddress, url } = dto;
|
||||||
|
|
||||||
const ISubmitMultiSig = new ethers.Interface([
|
const ISubmitMultiSig = new ethers.Interface([
|
||||||
@ -65,11 +68,14 @@ export class AgreementService extends BaseContractService {
|
|||||||
]);
|
]);
|
||||||
const data = ISubmitMultiSig.encodeFunctionData('request', [url]);
|
const data = ISubmitMultiSig.encodeFunctionData('request', [url]);
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,47 +9,72 @@ import {
|
|||||||
RequestLicenseDto,
|
RequestLicenseDto,
|
||||||
SetPayoutContractDto,
|
SetPayoutContractDto,
|
||||||
} from './license.dto';
|
} from './license.dto';
|
||||||
|
import { GetHeader } from '../../decorators/getHeader.decorator';
|
||||||
@ApiTags('license')
|
@ApiTags('license')
|
||||||
@Controller('license')
|
@Controller('license')
|
||||||
export class LicenseController {
|
export class LicenseController {
|
||||||
constructor(private readonly licenseService: LicenseService) {}
|
constructor(private readonly licenseService: LicenseService) {}
|
||||||
@Post('request')
|
@Post('request')
|
||||||
async getLicenseRequest(@Body() dto: RequestLicenseDto) {
|
async getLicenseRequest(
|
||||||
return this.licenseService.request(dto);
|
@Body() dto: RequestLicenseDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.request(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('deploy')
|
@Post('deploy')
|
||||||
async deploy(@Body() dto: DeployLicenseDto) {
|
async deploy(
|
||||||
return this.licenseService.deploy(dto);
|
@Body() dto: DeployLicenseDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.deploy(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('total-payout')
|
@Get('total-payout')
|
||||||
async getLicenseResponse(@Body() dto: GetLicenseInfoDto) {
|
async getLicenseResponse(
|
||||||
return this.licenseService.getTotalPayoutInUSD(dto);
|
@Body() dto: GetLicenseInfoDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.getTotalPayoutInUSD(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('shares')
|
@Get('shares')
|
||||||
async getShares(@Body() dto: GetShareLicense) {
|
async getShares(
|
||||||
return this.licenseService.getShares(dto);
|
@Body() dto: GetShareLicense,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.getShares(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('owners')
|
@Get('owners')
|
||||||
async getOwners(@Body() dto: GetLicenseInfoDto) {
|
async getOwners(
|
||||||
return this.licenseService.getOwners(dto);
|
@Body() dto: GetLicenseInfoDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.getOwners(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('payout-contract')
|
@Get('payout-contract')
|
||||||
async getPayoutContract(@Body() dto: GetLicenseInfoDto) {
|
async getPayoutContract(
|
||||||
return this.licenseService.getPayoutContract(dto);
|
@Body() dto: GetLicenseInfoDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.getPayoutContract(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('payout')
|
@Post('payout')
|
||||||
async payout(@Body() dto: LicensePayoutDto) {
|
async payout(
|
||||||
return this.licenseService.payout(dto);
|
@Body() dto: LicensePayoutDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.payout(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('set-payout-contract')
|
@Post('set-payout-contract')
|
||||||
async setPayoutContract(@Body() dto: SetPayoutContractDto) {
|
async setPayoutContract(
|
||||||
return this.licenseService.setPayoutContract(dto);
|
@Body() dto: SetPayoutContractDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.licenseService.setPayoutContract(dto, seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ export class LicenseService extends BaseContractService {
|
|||||||
) {
|
) {
|
||||||
super(providerService);
|
super(providerService);
|
||||||
}
|
}
|
||||||
async request(dto: RequestLicenseDto) {
|
async request(dto: RequestLicenseDto, seed: string) {
|
||||||
const { multiSigWallet, contractAddress, url } = dto;
|
const { multiSigWallet, contractAddress, url } = dto;
|
||||||
|
|
||||||
const ISubmitMultiSig = new ethers.Interface([
|
const ISubmitMultiSig = new ethers.Interface([
|
||||||
@ -30,20 +30,23 @@ export class LicenseService extends BaseContractService {
|
|||||||
]);
|
]);
|
||||||
const data = ISubmitMultiSig.encodeFunctionData('request', [url]);
|
const data = ISubmitMultiSig.encodeFunctionData('request', [url]);
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTotalPayoutInUSD(dto: GetLicenseInfoDto) {
|
async getTotalPayoutInUSD(dto: GetLicenseInfoDto, seed: string) {
|
||||||
const { contractAddress } = dto;
|
const { contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
const { abi } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
);
|
);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ export class LicenseService extends BaseContractService {
|
|||||||
return answer.toString();
|
return answer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
async deploy(dto: DeployLicenseDto) {
|
async deploy(dto: DeployLicenseDto, seed: string) {
|
||||||
const { multiSigWallet, shares, owners } = dto;
|
const { multiSigWallet, shares, owners } = dto;
|
||||||
const { bytecode } = await hre.artifacts.readArtifact(
|
const { bytecode } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
@ -80,22 +83,25 @@ export class LicenseService extends BaseContractService {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
const fullBytecode = bytecode + abiEncodedConstructorArguments.substring(2);
|
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: fullBytecode,
|
data: fullBytecode,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
delete submitData.data;
|
delete submitData.data;
|
||||||
return submitData;
|
return submitData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPayoutContract(dto: GetLicenseInfoDto) {
|
async getPayoutContract(dto: GetLicenseInfoDto, seed: string) {
|
||||||
const { contractAddress } = dto;
|
const { contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
const { abi } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
);
|
);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -104,12 +110,12 @@ export class LicenseService extends BaseContractService {
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOwners(dto: GetLicenseInfoDto) {
|
async getOwners(dto: GetLicenseInfoDto, seed: string) {
|
||||||
const { contractAddress } = dto;
|
const { contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
const { abi } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
);
|
);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -129,12 +135,12 @@ export class LicenseService extends BaseContractService {
|
|||||||
return owners;
|
return owners;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShares(dto: GetShareLicense) {
|
async getShares(dto: GetShareLicense, seed: string) {
|
||||||
const { contractAddress, ownerAddress } = dto;
|
const { contractAddress, ownerAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact(
|
const { abi } = await hre.artifacts.readArtifact(
|
||||||
'StreamingRightsManagement',
|
'StreamingRightsManagement',
|
||||||
);
|
);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -144,21 +150,24 @@ export class LicenseService extends BaseContractService {
|
|||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
async payout(dto: LicensePayoutDto) {
|
async payout(dto: LicensePayoutDto, seed: string) {
|
||||||
const { multiSigWallet, contractAddress } = dto;
|
const { multiSigWallet, contractAddress } = dto;
|
||||||
|
|
||||||
const ISubmitMultiSig = new ethers.Interface(['function payout()']);
|
const ISubmitMultiSig = new ethers.Interface(['function payout()']);
|
||||||
const data = ISubmitMultiSig.encodeFunctionData('payout');
|
const data = ISubmitMultiSig.encodeFunctionData('payout');
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setPayoutContract(dto: SetPayoutContractDto) {
|
async setPayoutContract(dto: SetPayoutContractDto, seed: string) {
|
||||||
const { multiSigWallet, contractAddress, payoutContract } = dto;
|
const { multiSigWallet, contractAddress, payoutContract } = dto;
|
||||||
|
|
||||||
const ISubmitMultiSig = new ethers.Interface([
|
const ISubmitMultiSig = new ethers.Interface([
|
||||||
@ -168,11 +177,14 @@ export class LicenseService extends BaseContractService {
|
|||||||
payoutContract,
|
payoutContract,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
RevokeConfirmationDto,
|
RevokeConfirmationDto,
|
||||||
SubmitTransactionDto,
|
SubmitTransactionDto,
|
||||||
} from '../multi-sig.dto';
|
} from '../multi-sig.dto';
|
||||||
|
import { GetHeader } from '../../decorators/getHeader.decorator';
|
||||||
@ApiTags('multi-sig')
|
@ApiTags('multi-sig')
|
||||||
@Controller('multi-sig')
|
@Controller('multi-sig')
|
||||||
export class MultiSigInteractController {
|
export class MultiSigInteractController {
|
||||||
@ -23,53 +24,81 @@ export class MultiSigInteractController {
|
|||||||
@Post('deploy')
|
@Post('deploy')
|
||||||
async deploy(
|
async deploy(
|
||||||
@Body() dto: MultiSigWalletDto,
|
@Body() dto: MultiSigWalletDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
): Promise<DeployMultiSigResponseDto> {
|
): Promise<DeployMultiSigResponseDto> {
|
||||||
const addr = await this.multiSigWalletService.deploy(dto);
|
const addr = await this.multiSigWalletService.deploy(dto, seed);
|
||||||
return {
|
return {
|
||||||
address: addr,
|
address: addr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@Get('owners/:address')
|
@Get('owners/:address')
|
||||||
async getOwners(@Param('address') address: string) {
|
async getOwners(
|
||||||
return this.multiSigWalletService.getOwners(address);
|
@Param('address') address: string,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.getOwners(address, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('submit-transaction')
|
@Post('submit-transaction')
|
||||||
async submitTransaction(@Body() dto: SubmitTransactionDto) {
|
async submitTransaction(
|
||||||
return this.multiSigWalletService.submitTransaction(dto);
|
@Body() dto: SubmitTransactionDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.submitTransaction(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('confirm-transaction')
|
@Post('confirm-transaction')
|
||||||
async confirmTransaction(@Body() dto: ConfirmTransactionDto) {
|
async confirmTransaction(
|
||||||
return this.multiSigWalletService.confirmTransaction(dto);
|
@Body() dto: ConfirmTransactionDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.confirmTransaction(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('execute-transaction')
|
@Post('execute-transaction')
|
||||||
async executeTransaction(@Body() dto: ExecuteTransactionDto) {
|
async executeTransaction(
|
||||||
return this.multiSigWalletService.executeTransaction(dto);
|
@Body() dto: ExecuteTransactionDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.executeTransaction(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('revoke-confirmation')
|
@Post('revoke-confirmation')
|
||||||
async revokeConfirmation(@Body() dto: RevokeConfirmationDto) {
|
async revokeConfirmation(
|
||||||
return this.multiSigWalletService.revokeConfirmation(dto);
|
@Body() dto: RevokeConfirmationDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.revokeConfirmation(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('transaction-count/:contractAddress')
|
@Get('transaction-count/:contractAddress')
|
||||||
async getTransactionCount(@Param('contractAddress') contractAddress: string) {
|
async getTransactionCount(
|
||||||
return this.multiSigWalletService.getTransactionCount(contractAddress);
|
@Param('contractAddress') contractAddress: string,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.getTransactionCount(
|
||||||
|
contractAddress,
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('transaction')
|
@Get('transaction')
|
||||||
async getTransaction(@Body() dto: GetTransactionDto) {
|
async getTransaction(
|
||||||
return this.multiSigWalletService.getTransaction(dto);
|
@Body() dto: GetTransactionDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.getTransaction(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('deposit')
|
@Post('deposit')
|
||||||
async deposit(@Body() dto: DepositContractDto) {
|
async deposit(
|
||||||
return this.multiSigWalletService.deposit(dto);
|
@Body() dto: DepositContractDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.multiSigWalletService.deposit(dto, seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ import { BaseContractService } from '../../base/base-contract.service';
|
|||||||
import { getContractAddress } from '@ethersproject/address';
|
import { getContractAddress } from '@ethersproject/address';
|
||||||
|
|
||||||
export class MultiSigWalletService extends BaseContractService {
|
export class MultiSigWalletService extends BaseContractService {
|
||||||
async deploy(dto: MultiSigWalletDto) {
|
async deploy(dto: MultiSigWalletDto, seed: string) {
|
||||||
const { abi, bytecode } =
|
const { abi, bytecode } =
|
||||||
await hre.artifacts.readArtifact('MultiSigWallet');
|
await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
|
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const salaryContract = new ethers.ContractFactory(abi, bytecode, signer);
|
const salaryContract = new ethers.ContractFactory(abi, bytecode, signer);
|
||||||
|
|
||||||
@ -30,20 +30,20 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
return myContract.getAddress();
|
return myContract.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOwners(address: string) {
|
async getOwners(address: string, seed: string) {
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
|
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(address, abi, signer);
|
const contract = new ethers.Contract(address, abi, signer);
|
||||||
|
|
||||||
return await contract.getOwners();
|
return await contract.getOwners();
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitTransaction(dto: SubmitTransactionDto) {
|
async submitTransaction(dto: SubmitTransactionDto, seed: string) {
|
||||||
const { destination, value, data, contractAddress } = dto;
|
const { destination, value, data, contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -66,10 +66,10 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async confirmTransaction(dto: ConfirmTransactionDto) {
|
async confirmTransaction(dto: ConfirmTransactionDto, seed: string) {
|
||||||
const { contractAddress, index } = dto;
|
const { contractAddress, index } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -86,10 +86,10 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeTransaction(dto: ExecuteTransactionDto) {
|
async executeTransaction(dto: ExecuteTransactionDto, seed: string) {
|
||||||
const { index, contractAddress, isDeploy } = dto;
|
const { index, contractAddress, isDeploy } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -134,45 +134,39 @@ export class MultiSigWalletService extends BaseContractService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async revokeConfirmation(dto: RevokeConfirmationDto) {
|
async revokeConfirmation(dto: RevokeConfirmationDto, seed: string) {
|
||||||
const { index, contractAddress } = dto;
|
const { index, contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const tx = await contract.revokeConfirmation(index);
|
return await contract.revokeConfirmation(index);
|
||||||
|
|
||||||
return tx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionCount(contractAddress: string) {
|
async getTransactionCount(contractAddress: string, seed: string) {
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const txCount = await contract.getTransactionCount();
|
return await contract.getTransactionCount();
|
||||||
|
|
||||||
return txCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransaction(dto: GetTransactionDto) {
|
async getTransaction(dto: GetTransactionDto, seed: string) {
|
||||||
const { index, contractAddress } = dto;
|
const { index, contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
const tx = await contract.getTransaction(index);
|
return await contract.getTransaction(index);
|
||||||
|
|
||||||
return tx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deposit(dto: DepositContractDto) {
|
async deposit(dto: DepositContractDto, seed: string) {
|
||||||
const { contractAddress, value } = dto;
|
const { contractAddress, value } = dto;
|
||||||
const convertValue = parseEther(value);
|
const convertValue = parseEther(value);
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
const { abi } = await hre.artifacts.readArtifact('MultiSigWallet');
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
} from './salaries.dto';
|
} from './salaries.dto';
|
||||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { DepositContractDto } from '../multi-sig.dto';
|
import { DepositContractDto } from '../multi-sig.dto';
|
||||||
|
import { GetHeader } from '../../decorators/getHeader.decorator';
|
||||||
|
|
||||||
@ApiTags('salaries')
|
@ApiTags('salaries')
|
||||||
@Controller('salaries')
|
@Controller('salaries')
|
||||||
@ -21,35 +22,51 @@ export class SalariesController {
|
|||||||
@Post('deploy')
|
@Post('deploy')
|
||||||
async deploy(
|
async deploy(
|
||||||
@Body() dto: SalariesDeployDto,
|
@Body() dto: SalariesDeployDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
): Promise<DeployContractResponseDto> {
|
): Promise<DeployContractResponseDto> {
|
||||||
const address = await this.salariesService.deploy(dto);
|
const address = await this.salariesService.deploy(dto, seed);
|
||||||
return {
|
return {
|
||||||
address,
|
address,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('usdt-price/:contractAddress')
|
@Get('usdt-price/:contractAddress')
|
||||||
async getUsdtPrice(@Param('contractAddress') contractAddress: string) {
|
async getUsdtPrice(
|
||||||
return this.salariesService.getLatestUSDTPrice(contractAddress);
|
@Param('contractAddress') contractAddress: string,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.salariesService.getLatestUSDTPrice(contractAddress, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('set-salary')
|
@Post('set-salary')
|
||||||
async setSalary(@Body() dto: SetSalaryDto) {
|
async setSalary(
|
||||||
return this.salariesService.setSalary(dto);
|
@Body() dto: SetSalaryDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.salariesService.setSalary(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('salary')
|
@Get('salary')
|
||||||
async getSalary(@Body() dto: GetEmployeeSalariesDto) {
|
async getSalary(
|
||||||
return this.salariesService.getSalary(dto);
|
@Body() dto: GetEmployeeSalariesDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.salariesService.getSalary(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('payout')
|
@Post('payout')
|
||||||
async createPayout(@Body() dto: CreatePayoutDto) {
|
async createPayout(
|
||||||
return this.salariesService.createPayout(dto);
|
@Body() dto: CreatePayoutDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.salariesService.createPayout(dto, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('deposit')
|
@Post('deposit')
|
||||||
async deposit(@Body() dto: DepositContractDto) {
|
async deposit(
|
||||||
return this.salariesService.deposit(dto);
|
@Body() dto: DepositContractDto,
|
||||||
|
@GetHeader('X-Seed') seed: string,
|
||||||
|
) {
|
||||||
|
return this.salariesService.deposit(dto, seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@ export class SalariesService extends BaseContractService {
|
|||||||
) {
|
) {
|
||||||
super(providerService);
|
super(providerService);
|
||||||
}
|
}
|
||||||
async deploy(dto: SalariesDeployDto) {
|
async deploy(dto: SalariesDeployDto, seed: string) {
|
||||||
const { abi, bytecode } = await hre.artifacts.readArtifact('Payroll');
|
const { abi, bytecode } = await hre.artifacts.readArtifact('Payroll');
|
||||||
|
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const salaryContract = new ethers.ContractFactory(abi, bytecode, signer);
|
const salaryContract = new ethers.ContractFactory(abi, bytecode, signer);
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ export class SalariesService extends BaseContractService {
|
|||||||
return await myContract.getAddress();
|
return await myContract.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLatestUSDTPrice(contractAddress: string) {
|
async getLatestUSDTPrice(contractAddress: string, seed: string) {
|
||||||
const { abi } = await hre.artifacts.readArtifact('Payroll');
|
const { abi } = await hre.artifacts.readArtifact('Payroll');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ export class SalariesService extends BaseContractService {
|
|||||||
return parseInt(answer) / 1e8;
|
return parseInt(answer) / 1e8;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setSalary(dto: SetSalaryDto) {
|
async setSalary(dto: SetSalaryDto, seed: string) {
|
||||||
const { employeeAddress, salary, contractAddress, multiSigWallet } = dto;
|
const { employeeAddress, salary, contractAddress, multiSigWallet } = dto;
|
||||||
const ISubmitMultiSig = new ethers.Interface([
|
const ISubmitMultiSig = new ethers.Interface([
|
||||||
'function setSalary(address employee, uint salaryInUSDT)',
|
'function setSalary(address employee, uint salaryInUSDT)',
|
||||||
@ -57,18 +57,21 @@ export class SalariesService extends BaseContractService {
|
|||||||
salary,
|
salary,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSalary(dto: GetEmployeeSalariesDto) {
|
async getSalary(dto: GetEmployeeSalariesDto, seed: string) {
|
||||||
const { employeeAddress, contractAddress } = dto;
|
const { employeeAddress, contractAddress } = dto;
|
||||||
const { abi } = await hre.artifacts.readArtifact('Payroll');
|
const { abi } = await hre.artifacts.readArtifact('Payroll');
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const contract = new ethers.Contract(contractAddress, abi, signer);
|
const contract = new ethers.Contract(contractAddress, abi, signer);
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ export class SalariesService extends BaseContractService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPayout(dto: CreatePayoutDto) {
|
async createPayout(dto: CreatePayoutDto, seed: string) {
|
||||||
const { employeeAddress, contractAddress, multiSigWallet } = dto;
|
const { employeeAddress, contractAddress, multiSigWallet } = dto;
|
||||||
const ISubmitMultiSig = new ethers.Interface([
|
const ISubmitMultiSig = new ethers.Interface([
|
||||||
'function payoutInETH(address employee)',
|
'function payoutInETH(address employee)',
|
||||||
@ -87,17 +90,20 @@ export class SalariesService extends BaseContractService {
|
|||||||
employeeAddress,
|
employeeAddress,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return await this.multiSigService.submitTransaction({
|
return await this.multiSigService.submitTransaction(
|
||||||
|
{
|
||||||
contractAddress: multiSigWallet,
|
contractAddress: multiSigWallet,
|
||||||
destination: contractAddress,
|
destination: contractAddress,
|
||||||
value: '0',
|
value: '0',
|
||||||
data,
|
data,
|
||||||
});
|
},
|
||||||
|
seed,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deposit(dto: DepositContractDto) {
|
async deposit(dto: DepositContractDto, seed: string) {
|
||||||
const { contractAddress, value } = dto;
|
const { contractAddress, value } = dto;
|
||||||
const signer = await this.providerService.getSigner();
|
const signer = await this.providerService.getSigner(seed);
|
||||||
|
|
||||||
const convertValue = parseEther(value);
|
const convertValue = parseEther(value);
|
||||||
|
|
||||||
|
8
chain-api/src/decorators/getHeader.decorator.ts
Normal file
8
chain-api/src/decorators/getHeader.decorator.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||||
|
|
||||||
|
export const GetHeader = createParamDecorator(
|
||||||
|
(data: string, ctx: ExecutionContext) => {
|
||||||
|
const request = ctx.switchToHttp().getRequest();
|
||||||
|
return request.headers[data.toLowerCase()];
|
||||||
|
},
|
||||||
|
);
|
@ -13,7 +13,7 @@ export class EthereumController {
|
|||||||
return this.ethereumService.getAddressFromPrivateKey(privateKey);
|
return this.ethereumService.getAddressFromPrivateKey(privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/address-from-seed')
|
@Post('/address-from-seed ')
|
||||||
async getAddressFromSeedPhrase(@Body() body: GetSeedPhraseDto) {
|
async getAddressFromSeedPhrase(@Body() body: GetSeedPhraseDto) {
|
||||||
return this.ethereumService.getAddressFromSeedPhrase(body.seedPhrase);
|
return this.ethereumService.getAddressFromSeedPhrase(body.seedPhrase);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user