增加获取实时订单信息的方法
This commit is contained in:
parent
01c4789cbe
commit
faa45df02c
@ -1,16 +1,16 @@
|
||||
import assert from "assert";
|
||||
import Web3 from "web3";
|
||||
import { abiMinterFactory } from "../abis/abiUserMinterFactory";
|
||||
import { GAS_BOOST, ZERO_ADDRESS } from "../config/constants";
|
||||
import { getAddressByName, universalChainCb } from "../util/chain.util";
|
||||
import { SAMPLE_GAS } from "./ChainCommon";
|
||||
import { abiMarket } from "../abis/abiMarket";
|
||||
import { abiMall } from "../abis/abiMall";
|
||||
import { abiGameMarket } from "../abis/abiGameMarket";
|
||||
import { abiGameMall } from "../abis/abiGameMall";
|
||||
import { ZError } from "../common/ZError";
|
||||
import { abiERC20 } from "../abis/abiERC20";
|
||||
import { abiERC721 } from "../abis/abiERC721";
|
||||
import assert from 'assert';
|
||||
import Web3 from 'web3';
|
||||
import { abiMinterFactory } from '../abis/abiUserMinterFactory';
|
||||
import { GAS_BOOST, ZERO_ADDRESS } from '../config/constants';
|
||||
import { getAddressByName, universalChainCb } from '../util/chain.util';
|
||||
import { SAMPLE_GAS } from './ChainCommon';
|
||||
import { abiMarket } from '../abis/abiMarket';
|
||||
import { abiMall } from '../abis/abiMall';
|
||||
import { abiGameMarket } from '../abis/abiGameMarket';
|
||||
import { abiGameMall } from '../abis/abiGameMall';
|
||||
import { ZError } from '../common/ZError';
|
||||
import { abiERC20 } from '../abis/abiERC20';
|
||||
import { abiERC721 } from '../abis/abiERC721';
|
||||
|
||||
export class JCStandard {
|
||||
private web3: Web3;
|
||||
@ -38,19 +38,13 @@ export class JCStandard {
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
const addressFactory = cfg.contracts.minterFactory;
|
||||
console.log("addressFactory:: ", addressFactory);
|
||||
const contract = new this.web3.eth.Contract(
|
||||
abiMinterFactory,
|
||||
addressFactory,
|
||||
{
|
||||
console.log('addressFactory:: ', addressFactory);
|
||||
const contract = new this.web3.eth.Contract(abiMinterFactory, addressFactory, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
}
|
||||
);
|
||||
});
|
||||
if (!gas) {
|
||||
gas = await contract.methods
|
||||
.mintNft(address, tokenIds, startTime, saltNonce, signature)
|
||||
.estimateGas();
|
||||
gas = await contract.methods.mintNft(address, tokenIds, startTime, saltNonce, signature).estimateGas();
|
||||
}
|
||||
gas = (gas * GAS_BOOST) | 1;
|
||||
if (estimate) {
|
||||
@ -68,14 +62,12 @@ export class JCStandard {
|
||||
}
|
||||
const logData = {
|
||||
gas,
|
||||
title: "mint_nft",
|
||||
title: 'mint_nft',
|
||||
details: details,
|
||||
};
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods
|
||||
.mintNft(address, tokenIds, startTime, saltNonce, signature)
|
||||
.send({ gas })
|
||||
contract.methods.mintNft(address, tokenIds, startTime, saltNonce, signature).send({ gas })
|
||||
);
|
||||
}
|
||||
// begin of NFT Market
|
||||
@ -97,9 +89,9 @@ export class JCStandard {
|
||||
estimate: number;
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressMarket = cfg.contracts.nftmarket;
|
||||
console.log("addressMarket:: ", addressMarket);
|
||||
console.log('addressMarket:: ', addressMarket);
|
||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -137,21 +129,14 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "market_sell",
|
||||
title: 'market_sell',
|
||||
details: details,
|
||||
};
|
||||
if (approved != addressMarket) {
|
||||
await tokenInstance.methods
|
||||
.approve(addressMarket, tokenId)
|
||||
.send({ gas: gasApprove });
|
||||
console.log("approve done");
|
||||
await tokenInstance.methods.approve(addressMarket, tokenId).send({ gas: gasApprove });
|
||||
console.log('approve done');
|
||||
}
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods
|
||||
.sell(nftToken, currency, tokenId, price, amount)
|
||||
.send({ gas })
|
||||
);
|
||||
return universalChainCb(logData, contract.methods.sell(nftToken, currency, tokenId, price, amount).send({ gas }));
|
||||
}
|
||||
|
||||
async marketUpdatePrice({
|
||||
@ -166,9 +151,9 @@ export class JCStandard {
|
||||
estimate: number;
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressMarket = cfg.contracts.nftmarket;
|
||||
console.log("addressMarket:: ", addressMarket);
|
||||
console.log('addressMarket:: ', addressMarket);
|
||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -192,28 +177,17 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "market_update_price",
|
||||
title: 'market_update_price',
|
||||
details: details,
|
||||
};
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods.updatePrice(orderId, price).send({ gas })
|
||||
);
|
||||
return universalChainCb(logData, contract.methods.updatePrice(orderId, price).send({ gas }));
|
||||
}
|
||||
|
||||
async marketCancelOrder({
|
||||
orderId,
|
||||
gas,
|
||||
estimate,
|
||||
}: {
|
||||
orderId: string;
|
||||
gas?: number;
|
||||
estimate: number;
|
||||
}) {
|
||||
async marketCancelOrder({ orderId, gas, estimate }: { orderId: string; gas?: number; estimate: number }) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressMarket = cfg.contracts.nftmarket;
|
||||
console.log("addressMarket:: ", addressMarket);
|
||||
console.log('addressMarket:: ', addressMarket);
|
||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -237,28 +211,17 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "market_cancel_order",
|
||||
title: 'market_cancel_order',
|
||||
details: details,
|
||||
};
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods.cancelOrder(orderId).send({ gas })
|
||||
);
|
||||
return universalChainCb(logData, contract.methods.cancelOrder(orderId).send({ gas }));
|
||||
}
|
||||
|
||||
async marketBuy({
|
||||
orderId,
|
||||
gas,
|
||||
estimate,
|
||||
}: {
|
||||
orderId: string;
|
||||
gas?: number;
|
||||
estimate: number;
|
||||
}) {
|
||||
async marketBuy({ orderId, gas, estimate }: { orderId: string; gas?: number; estimate: number }) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressMarket = cfg.contracts.nftmarket;
|
||||
console.log("addressMarket:: ", addressMarket);
|
||||
console.log('addressMarket:: ', addressMarket);
|
||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -267,18 +230,12 @@ export class JCStandard {
|
||||
if (!orderInfo.orderId) {
|
||||
throw new ZError(100, `order info with id: ${orderId} not found`);
|
||||
}
|
||||
const tokenInstance = new this.web3.eth.Contract(
|
||||
abiERC20,
|
||||
orderInfo.currency,
|
||||
{
|
||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, orderInfo.currency, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
}
|
||||
);
|
||||
let approved = await tokenInstance.methods
|
||||
.allowance(jc.wallet.currentAccAddr, addressMarket)
|
||||
.call();
|
||||
console.log("approved:: ", approved);
|
||||
});
|
||||
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressMarket).call();
|
||||
console.log('approved:: ', approved);
|
||||
let gasApprove = 0;
|
||||
if (approved < orderInfo.price) {
|
||||
gasApprove = cfg.gasInfo.cecApprove;
|
||||
@ -305,20 +262,26 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "market_buy",
|
||||
title: 'market_buy',
|
||||
details: details,
|
||||
};
|
||||
if (approved < orderInfo.price) {
|
||||
await tokenInstance.methods
|
||||
.approve(addressMarket, orderInfo.price)
|
||||
.send({ gas: gasApprove });
|
||||
await tokenInstance.methods.approve(addressMarket, orderInfo.price).send({ gas: gasApprove });
|
||||
}
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods.buy(orderId).send({ gas })
|
||||
);
|
||||
return universalChainCb(logData, contract.methods.buy(orderId).send({ gas }));
|
||||
}
|
||||
|
||||
async marketOrderInfo(orderId: string) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
const addressMarket = cfg.contracts.nftmarket;
|
||||
console.log('addressMarket:: ', addressMarket);
|
||||
const contract = new this.web3.eth.Contract(abiMarket, addressMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
});
|
||||
let orderInfo = await contract.methods.orderInfos(orderId).call();
|
||||
return orderInfo;
|
||||
}
|
||||
// end of NFT Market
|
||||
|
||||
// begin of game item mall
|
||||
@ -342,9 +305,9 @@ export class JCStandard {
|
||||
estimate: number;
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressGameMall = cfg.contracts.gamemall;
|
||||
console.log("addressGameMall:: ", addressGameMall);
|
||||
console.log('addressGameMall:: ', addressGameMall);
|
||||
const contract = new this.web3.eth.Contract(abiGameMall, addressGameMall, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -353,10 +316,8 @@ export class JCStandard {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
});
|
||||
let approved = await tokenInstance.methods
|
||||
.allowance(jc.wallet.currentAccAddr, addressGameMall)
|
||||
.call();
|
||||
console.log("approved:: ", approved);
|
||||
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressGameMall).call();
|
||||
console.log('approved:: ', approved);
|
||||
let gasApprove = 0;
|
||||
if (approved < price) {
|
||||
gasApprove = cfg.gasInfo.cecApprove;
|
||||
@ -383,25 +344,20 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "game_mall_buy",
|
||||
title: 'game_mall_buy',
|
||||
details: details,
|
||||
};
|
||||
if (approved < price) {
|
||||
await tokenInstance.methods
|
||||
.approve(addressGameMall, price)
|
||||
.send({ gas: gasApprove });
|
||||
await tokenInstance.methods.approve(addressGameMall, price).send({ gas: gasApprove });
|
||||
}
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods
|
||||
.buy(orderId, currency, price, startTime, saltNonce, signature)
|
||||
.send({ gas })
|
||||
contract.methods.buy(orderId, currency, price, startTime, saltNonce, signature).send({ gas })
|
||||
);
|
||||
}
|
||||
// end of game item mall
|
||||
|
||||
// begin of game item market
|
||||
// TODO:: test
|
||||
async gameMarketBuy({
|
||||
orderId,
|
||||
seller,
|
||||
@ -424,31 +380,25 @@ export class JCStandard {
|
||||
estimate: number;
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressGameMarket = cfg.contracts.gamemarket;
|
||||
console.log("addressGameMarket:: ", addressGameMarket);
|
||||
const contract = new this.web3.eth.Contract(
|
||||
abiGameMarket,
|
||||
addressGameMarket,
|
||||
{
|
||||
console.log('addressGameMarket:: ', addressGameMarket);
|
||||
const contract = new this.web3.eth.Contract(abiGameMarket, addressGameMarket, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
}
|
||||
);
|
||||
});
|
||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
});
|
||||
let approved = await tokenInstance.methods
|
||||
.allowance(jc.wallet.currentAccAddr, addressGameMarket)
|
||||
.call();
|
||||
console.log("approved:: ", approved);
|
||||
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressGameMarket).call();
|
||||
console.log('approved:: ', approved);
|
||||
let gasApprove = 0;
|
||||
if (approved < price) {
|
||||
gasApprove = cfg.gasInfo.cecApprove;
|
||||
}
|
||||
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||
console.log("gasApprove: " + gasApprove);
|
||||
console.log('gasApprove: ' + gasApprove);
|
||||
if (!gas) {
|
||||
// gas = await contract.methods
|
||||
// .buy(orderId, seller, currency, price, startTime, saltNonce, signature)
|
||||
@ -456,7 +406,7 @@ export class JCStandard {
|
||||
gas = cfg.gasInfo.gameMarketBuy;
|
||||
}
|
||||
gas = (gas * GAS_BOOST) | 1;
|
||||
console.log("gas: " + gas);
|
||||
console.log('gas: ' + gas);
|
||||
|
||||
if (estimate) {
|
||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||
@ -472,19 +422,15 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "game_market_buy",
|
||||
title: 'game_market_buy',
|
||||
details: details,
|
||||
};
|
||||
if (approved < price) {
|
||||
await tokenInstance.methods
|
||||
.approve(addressGameMarket, price)
|
||||
.send({ gas: gasApprove });
|
||||
await tokenInstance.methods.approve(addressGameMarket, price).send({ gas: gasApprove });
|
||||
}
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods
|
||||
.buy(orderId, seller, currency, price, startTime, saltNonce, signature)
|
||||
.send({ gas })
|
||||
contract.methods.buy(orderId, seller, currency, price, startTime, saltNonce, signature).send({ gas })
|
||||
);
|
||||
}
|
||||
// end of game item market
|
||||
@ -502,9 +448,9 @@ export class JCStandard {
|
||||
estimate: number;
|
||||
}) {
|
||||
const cfg = jc.wallet.currentChainCfg;
|
||||
estimate = parseInt(estimate + "");
|
||||
estimate = parseInt(estimate + '');
|
||||
const addressMall = cfg.contracts.nftmall;
|
||||
console.log("addressMall:: ", addressMall);
|
||||
console.log('addressMall:: ', addressMall);
|
||||
const contract = new this.web3.eth.Contract(abiMall, addressMall, {
|
||||
//@ts-ignore
|
||||
from: jc.wallet.currentAccAddr,
|
||||
@ -515,17 +461,13 @@ export class JCStandard {
|
||||
gas = (gas * GAS_BOOST) | 1;
|
||||
|
||||
const tokenInstance = new this.web3.eth.Contract(abiERC20, addresses[2]);
|
||||
let gasApprove = await tokenInstance.methods
|
||||
.approve(addressMall, values[1])
|
||||
.estimateGas();
|
||||
let gasApprove = await tokenInstance.methods.approve(addressMall, values[1]).estimateGas();
|
||||
gasApprove = (gasApprove * GAS_BOOST) | 1;
|
||||
|
||||
if (estimate) {
|
||||
return jc.wallet.generateGasShow(gas + gasApprove);
|
||||
}
|
||||
await tokenInstance.methods
|
||||
.approve(addressMall, values[1])
|
||||
.sent({ gas: gasApprove });
|
||||
await tokenInstance.methods.approve(addressMall, values[1]).sent({ gas: gasApprove });
|
||||
|
||||
let details = [
|
||||
{
|
||||
@ -549,13 +491,10 @@ export class JCStandard {
|
||||
];
|
||||
const logData = {
|
||||
gas,
|
||||
title: "mall_buy_nft",
|
||||
title: 'mall_buy_nft',
|
||||
details: details,
|
||||
};
|
||||
return universalChainCb(
|
||||
logData,
|
||||
contract.methods.buyNFT(addresses, values).send({ gas })
|
||||
);
|
||||
return universalChainCb(logData, contract.methods.buyNFT(addresses, values).send({ gas }));
|
||||
}
|
||||
// end of NFT Mall
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user