修改nftmall的购买方式

This commit is contained in:
CounterFire2023 2023-06-21 11:24:12 +08:00
parent faa45df02c
commit e0591c1be5
5 changed files with 448 additions and 814 deletions

View File

@ -1,509 +0,0 @@
import { AbiItem } from "web3-utils";
export let abiNftMall: AbiItem[] = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "buyer",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "nonce",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
],
name: "BuyTransaction",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "buyer",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "nonce",
type: "uint256",
},
{
indexed: false,
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
{
indexed: false,
internalType: "uint256[]",
name: "ids",
type: "uint256[]",
},
{
indexed: false,
internalType: "uint256[]",
name: "amounts",
type: "uint256[]",
},
],
name: "BuyTransactionBatch",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "OwnershipTransferred",
type: "event",
},
{
inputs: [
{
internalType: "address",
name: "user",
type: "address",
},
],
name: "addApprovalList",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "signer",
type: "address",
},
{
internalType: "bytes32",
name: "hash",
type: "bytes32",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "checkSigner",
outputs: [],
stateMutability: "pure",
type: "function",
constant: true,
},
{
inputs: [
{
internalType: "address",
name: "signer",
type: "address",
},
{
internalType: "bytes32",
name: "structHash",
type: "bytes32",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "checkSigner712",
outputs: [],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [],
name: "feeToAddress",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [],
name: "getDuration",
outputs: [
{
internalType: "uint256",
name: "duration",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "nftTokenSupported",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "paymentTokens",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [
{
internalType: "address",
name: "user",
type: "address",
},
],
name: "removeApprovalList",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "renounceOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "transferOwnership",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "valNew",
type: "uint256",
},
],
name: "updateDuation",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "useSignature",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "bytes",
name: "",
type: "bytes",
},
],
name: "usedSignatures",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
constant: true,
},
{
inputs: [
{
internalType: "address",
name: "_feeToAddress",
type: "address",
},
],
name: "setFeeToAddress",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address[]",
name: "_paymentTokens",
type: "address[]",
},
],
name: "setPaymentTokens",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address[]",
name: "_removedPaymentTokens",
type: "address[]",
},
],
name: "removePaymentTokens",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "nftToken",
type: "address",
},
],
name: "addNFTTokenSupport",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "nftToken",
type: "address",
},
],
name: "removeNFTTokenSupport",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address[4]",
name: "addresses",
type: "address[4]",
},
{
internalType: "uint256[]",
name: "signArray",
type: "uint256[]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "ignoreSignature",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
internalType: "uint256[4]",
name: "values",
type: "uint256[4]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "buy721NFT",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
internalType: "uint256[3]",
name: "values",
type: "uint256[3]",
},
{
internalType: "uint256[]",
name: "ids",
type: "uint256[]",
},
{
internalType: "uint256[]",
name: "amounts",
type: "uint256[]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
},
],
name: "buy1155NFT",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "_nftAddress",
type: "address",
},
{
internalType: "address",
name: "_tokenAddress",
type: "address",
},
{
internalType: "address",
name: "_buyerAddress",
type: "address",
},
{
internalType: "uint256[]",
name: "_datas",
type: "uint256[]",
},
],
name: "getMessageHash",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
},
],
stateMutability: "pure",
type: "function",
constant: true,
},
];

View File

@ -1,418 +1,493 @@
import { AbiItem } from "web3-utils";
import { AbiItem } from 'web3-utils';
export let abiMall: AbiItem[] = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
stateMutability: 'nonpayable',
type: 'constructor',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "erc20",
type: "address",
internalType: 'address',
name: 'erc20',
type: 'address',
},
],
name: "AddERC20Suppout",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "buyer",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "nonce",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
],
name: "BuyTransaction",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "previousOwner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "newOwner",
type: "address",
},
],
name: "OwnershipTransferred",
type: "event",
name: 'AddERC20Suppout',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "erc20",
type: "address",
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: "RemoveERC20Suppout",
type: "event",
name: 'AddNFTSuppout',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'buyer',
type: 'address',
},
{
indexed: true,
internalType: 'uint256',
name: 'orderId',
type: 'uint256',
},
{
indexed: false,
internalType: 'address',
name: 'currency',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'price',
type: 'uint256',
},
{
indexed: false,
internalType: 'address[]',
name: 'nftAddresses',
type: 'address[]',
},
{
indexed: false,
internalType: 'uint256[]',
name: 'ids',
type: 'uint256[]',
},
{
indexed: false,
internalType: 'uint256[]',
name: 'amounts',
type: 'uint256[]',
},
],
name: 'BuyTransaction',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'previousOwner',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'newOwner',
type: 'address',
},
],
name: 'OwnershipTransferred',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'erc20',
type: 'address',
},
],
name: 'RemoveERC20Suppout',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: 'RemoveNFTSuppout',
type: 'event',
},
{
inputs: [
{
internalType: "address",
name: "erc20",
type: "address",
internalType: 'address',
name: 'erc20',
type: 'address',
},
],
name: "addERC20Support",
name: 'addERC20Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "signer",
type: "address",
internalType: 'address',
name: 'signer',
type: 'address',
},
{
internalType: "bytes32",
name: "hash",
type: "bytes32",
internalType: 'bytes32',
name: 'hash',
type: 'bytes32',
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
internalType: 'bytes',
name: 'signature',
type: 'bytes',
},
],
name: "checkSigner",
name: 'checkSigner',
outputs: [],
stateMutability: "pure",
type: "function",
stateMutability: 'pure',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "signer",
type: "address",
internalType: 'address',
name: 'signer',
type: 'address',
},
{
internalType: "bytes32",
name: "structHash",
type: "bytes32",
internalType: 'bytes32',
name: 'structHash',
type: 'bytes32',
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
internalType: 'bytes',
name: 'signature',
type: 'bytes',
},
],
name: "checkSigner712",
name: 'checkSigner712',
outputs: [],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
internalType: 'address',
name: '',
type: 'address',
},
],
name: "erc20Supported",
name: 'erc1155Supported',
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'erc20Supported',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'erc721Supported',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: "executor",
name: 'executor',
outputs: [
{
internalType: "address",
name: "",
type: "address",
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: "feeToAddress",
name: 'feeToAddress',
outputs: [
{
internalType: "address",
name: "",
type: "address",
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: "getDuration",
name: 'getDuration',
outputs: [
{
internalType: "uint256",
name: "duration",
type: "uint256",
internalType: 'uint256',
name: 'duration',
type: 'uint256',
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "nftTokenSupported",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: "owner",
name: 'owner',
outputs: [
{
internalType: "address",
name: "",
type: "address",
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: "view",
type: "function",
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "erc20",
type: "address",
internalType: 'address',
name: 'erc20',
type: 'address',
},
],
name: "removeERC20Support",
name: 'removeERC20Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: "renounceOwnership",
name: 'renounceOwnership',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "_feeToAddress",
type: "address",
internalType: 'address',
name: '_feeToAddress',
type: 'address',
},
],
name: "setFeeToAddress",
name: 'setFeeToAddress',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "newOwner",
type: "address",
internalType: 'address',
name: 'newOwner',
type: 'address',
},
],
name: "transferOwnership",
name: 'transferOwnership',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "uint256",
name: "valNew",
type: "uint256",
internalType: 'uint256',
name: 'valNew',
type: 'uint256',
},
],
name: "updateDuation",
name: 'updateDuation',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address",
internalType: 'address',
name: 'account',
type: 'address',
},
],
name: "updateExecutor",
name: 'updateExecutor',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "nftToken",
type: "address",
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: "addNFTTokenSupport",
name: 'addERC721Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "nftToken",
type: "address",
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: "removeNFTTokenSupport",
name: 'removeERC721Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address[4]",
name: "addresses",
type: "address[4]",
},
{
internalType: "uint256[]",
name: "signArray",
type: "uint256[]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: "ignoreSignature",
name: 'addERC1155Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address[3]",
name: "addresses",
type: "address[3]",
},
{
internalType: "uint256[4]",
name: "values",
type: "uint256[4]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
internalType: 'address',
name: 'nftToken',
type: 'address',
},
],
name: "buyNFT",
name: 'removeERC1155Support',
outputs: [],
stateMutability: "nonpayable",
type: "function",
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "_nftAddress",
type: "address",
internalType: 'address',
name: 'currency',
type: 'address',
},
{
internalType: "address",
name: "_tokenAddress",
type: "address",
internalType: 'address[]',
name: 'nftAddresses',
type: 'address[]',
},
{
internalType: "address",
name: "_buyerAddress",
type: "address",
internalType: 'uint256[]',
name: 'ids',
type: 'uint256[]',
},
{
internalType: "uint256[]",
name: "_datas",
type: "uint256[]",
internalType: 'uint256[]',
name: 'amounts',
type: 'uint256[]',
},
{
internalType: 'uint256[]',
name: 'values',
type: 'uint256[]',
},
{
internalType: 'bytes',
name: 'signature',
type: 'bytes',
},
],
name: "getMessageHash",
name: 'buyNFT',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '_tokenAddress',
type: 'address',
},
{
internalType: 'address',
name: '_buyerAddress',
type: 'address',
},
{
internalType: 'address[]',
name: '_nftAddresses',
type: 'address[]',
},
{
internalType: 'uint256[]',
name: '_datas',
type: 'uint256[]',
},
],
name: 'getMessageHash',
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
stateMutability: "pure",
type: "function",
stateMutability: 'pure',
type: 'function',
},
];

View File

@ -1,45 +1,45 @@
module.exports = {
tokens: [
{
type: "eth",
address: "eth",
symbol: "AGOR",
type: 'eth',
address: 'eth',
symbol: 'AGOR',
decimal: 18,
},
{
type: "erc20",
address: "0x8dd1439E0C3254b4543d6D68b3C0C891E5Bd2eCE",
symbol: "CEC",
type: 'erc20',
address: '0x8dd1439E0C3254b4543d6D68b3C0C891E5Bd2eCE',
symbol: 'CEC',
decimal: 18,
},
{
type: "erc20",
address: "0x2C7221588D4FBac2585D71618CD540e74c7413B8",
symbol: "CEG",
type: 'erc20',
address: '0x2C7221588D4FBac2585D71618CD540e74c7413B8',
symbol: 'CEG',
decimal: 18,
},
{
address: "0xE6A69474E04B93De50dd07F239d62879dB9bF716",
name: "hero",
type: "erc721",
address: '0xE6A69474E04B93De50dd07F239d62879dB9bF716',
name: 'hero',
type: 'erc721',
},
{
address: "0x8Ce844402bE22fA1276a375Ff2354DD27aDEF285",
name: "weapon",
type: "erc721",
address: '0x8Ce844402bE22fA1276a375Ff2354DD27aDEF285',
name: 'weapon',
type: 'erc721',
},
{
address: "0x4678fE0177B15538F441264cB851364d9F3872AA",
name: "chip",
type: "erc721",
address: '0x4678fE0177B15538F441264cB851364d9F3872AA',
name: 'chip',
type: 'erc721',
},
],
contracts: {
minterFactory: "0x1A27515c35a92Fb276c2670fa27C85ffAd75D094",
nftmarket: "0x28cd862Baa826e65a0c0F1179B9A3423dF4d366A",
nftmall: "0x38Bf9f3C29D8384B6A79435745AE796cd2465545",
gamemarket: "0x46e2C612756b702b3d68d89F97c88FFa725F6fab",
gamemall: "0x1D058c7c7451c34BbfF9c0dF1C16b95C5d171d64",
minterFactory: '0x1A27515c35a92Fb276c2670fa27C85ffAd75D094',
nftmarket: '0x28cd862Baa826e65a0c0F1179B9A3423dF4d366A',
nftmall: '0x4d71dE0428328112A78D402A6fdd7ceD1C96B71e',
gamemarket: '0x46e2C612756b702b3d68d89F97c88FFa725F6fab',
gamemall: '0x1D058c7c7451c34BbfF9c0dF1C16b95C5d171d64',
},
gasInfo: {
nftApprove: 49340,

View File

@ -1,15 +1,16 @@
import { records } from "../api/RecordApi";
import { singleton } from "../decorator/singleton.decorator";
import { records } from '../api/RecordApi';
import { singleton } from '../decorator/singleton.decorator';
@singleton
export class TranHistorySvr {
/**
* eth history
*/
public async ethRecords(start: number, limit: number) {
public async ethRecords(start: number, limit: number, moreParam: any) {
start = start | 0;
limit = limit | 0;
const data = { start, limit, chain: jc.wallet.currentChain.id };
let data = { start, limit, chain: jc.wallet.currentChain.id };
Object.assign(data, moreParam);
return records(data);
}
@ -21,23 +22,26 @@ export class TranHistorySvr {
tokenId,
start,
limit,
moreParam,
}: {
address: string;
tokenId?: string;
start: number;
limit: number;
moreParam: any;
}) {
start = start | 0;
limit = limit | 0;
const data: any = {
let data: any = {
start,
limit,
chain: jc.wallet.currentChain.id,
"details.address": address,
'details.address': address,
};
if (tokenId) {
data["details.id"] = tokenId + "";
data['details.id'] = tokenId + '';
}
Object.assign(data, moreParam);
return records(data);
}
}

View File

@ -51,7 +51,13 @@ export class JCStandard {
return jc.wallet.generateGasShow(gas);
}
let details = [];
let details: any[] = [
{
address: addressFactory,
from: jc.wallet.currentAccAddr,
to: addressFactory,
},
];
for (let tokenId of tokenIds) {
details.push({
address,
@ -119,7 +125,12 @@ export class JCStandard {
return jc.wallet.generateGasShow(gas + gasApprove);
}
let details = [
let details: any = [
{
address: addressMarket,
from: jc.wallet.currentAccAddr,
to: addressMarket,
},
{
address: nftToken,
from: jc.wallet.currentAccAddr,
@ -172,7 +183,6 @@ export class JCStandard {
address: addressMarket,
from: jc.wallet.currentAccAddr,
to: addressMarket,
value: 0,
},
];
const logData = {
@ -200,13 +210,21 @@ export class JCStandard {
if (estimate) {
return jc.wallet.generateGasShow(gas);
}
let orderInfo = await contract.methods.orderInfos(orderId).call();
if (!orderInfo.orderId) {
throw new ZError(100, `order info with id: ${orderId} not found`);
}
let details = [
{
address: addressMarket,
from: jc.wallet.currentAccAddr,
to: addressMarket,
value: 0,
},
{
address: orderInfo.nftToken,
from: addressMarket,
to: jc.wallet.currentAccAddr,
id: orderInfo.tokenId,
},
];
const logData = {
@ -251,13 +269,25 @@ export class JCStandard {
if (estimate) {
return jc.wallet.generateGasShow(gas + gasApprove);
}
//TODO:: 记录详细的转账记录, -> seller, -> txFeeAddress, -> txTaxAddress
let details = [
{
address: addressMarket,
from: jc.wallet.currentAccAddr,
to: addressMarket,
value: 0,
},
{
address: orderInfo.nftToken,
from: addressMarket,
to: jc.wallet.currentAccAddr,
id: orderInfo.tokenId,
value: orderInfo.amount,
},
{
address: orderInfo.currency,
from: jc.wallet.currentAccAddr,
to: addressMarket,
id: orderInfo.price,
},
];
const logData = {
@ -333,13 +363,18 @@ export class JCStandard {
if (estimate) {
return jc.wallet.generateGasShow(gas + gasApprove);
}
// TOTO::
let feeAddress = await contract.methods.feeToAddress().call();
let details = [
{
address: addressGameMall,
from: jc.wallet.currentAccAddr,
to: addressGameMall,
value: 0,
},
{
address: currency,
from: jc.wallet.currentAccAddr,
to: feeAddress,
value: price,
},
];
const logData = {
@ -411,13 +446,18 @@ export class JCStandard {
if (estimate) {
return jc.wallet.generateGasShow(gas + gasApprove);
}
let feeAddress = await contract.methods.feeToAddress().call();
let details = [
{
address: addressGameMarket,
from: jc.wallet.currentAccAddr,
to: addressGameMarket,
value: 0,
},
{
address: currency,
from: jc.wallet.currentAccAddr,
to: feeAddress,
value: price,
},
];
const logData = {
@ -435,15 +475,27 @@ export class JCStandard {
}
// end of game item market
// begin of NFT Mall
// TODO:: test
/**
*
* @param values: [orderId, price, startTime, saltNonce]
* @returns
*/
async mallBuy({
currency,
addresses,
ids,
amounts,
values,
signature,
gas,
estimate,
}: {
currency: string;
addresses: string[];
ids: string[];
amounts: string[];
values: string[];
signature: string;
gas?: number;
estimate: number;
}) {
@ -455,46 +507,58 @@ export class JCStandard {
//@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, addressMall).call();
console.log('approved:: ', approved);
let gasApprove = 0;
if (approved < values[1]) {
gasApprove = cfg.gasInfo.cecApprove;
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressMall, values[1]).send({ gas: gasApprove });
}
if (!gas) {
gas = await contract.methods.buyNFT(addresses, values).estimateGas();
gas = await contract.methods.buyNFT(currency, addresses, ids, amounts, values, signature).estimateGas();
}
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();
gasApprove = (gasApprove * GAS_BOOST) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas + gasApprove);
}
await tokenInstance.methods.approve(addressMall, values[1]).sent({ gas: gasApprove });
let details = [
let details: any = [
{
address: addressMall,
from: jc.wallet.currentAccAddr,
to: addressMall,
value: 0,
},
{
address: addresses[1],
from: addresses[0],
to: jc.wallet.currentAccAddr,
value: values[0],
},
{
address: addresses[2],
address: currency,
from: jc.wallet.currentAccAddr,
to: addresses[0],
to: addressMall,
value: values[1],
},
];
for (let i = 0; i < addresses.length; i++) {
details.push({
address: addresses[i],
from: jc.wallet.currentAccAddr,
to: jc.wallet.currentAccAddr,
value: values[i],
id: ids[i],
});
}
const logData = {
gas,
title: 'mall_buy_nft',
details: details,
};
return universalChainCb(logData, contract.methods.buyNFT(addresses, values).send({ gas }));
return universalChainCb(
logData,
contract.methods.buyNFT(currency, addresses, ids, amounts, values, signature).send({ gas })
);
}
// end of NFT Mall
}