修改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[] = [ export let abiMall: AbiItem[] = [
{ {
inputs: [], inputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "constructor", type: 'constructor',
}, },
{ {
anonymous: false, anonymous: false,
inputs: [ inputs: [
{ {
indexed: false, indexed: false,
internalType: "address", internalType: 'address',
name: "erc20", name: 'erc20',
type: "address", type: 'address',
}, },
], ],
name: "AddERC20Suppout", name: 'AddERC20Suppout',
type: "event", 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",
}, },
{ {
anonymous: false, anonymous: false,
inputs: [ inputs: [
{ {
indexed: false, indexed: false,
internalType: "address", internalType: 'address',
name: "erc20", name: 'nftToken',
type: "address", type: 'address',
}, },
], ],
name: "RemoveERC20Suppout", name: 'AddNFTSuppout',
type: "event", 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: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "erc20", name: 'erc20',
type: "address", type: 'address',
}, },
], ],
name: "addERC20Support", name: 'addERC20Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "signer", name: 'signer',
type: "address", type: 'address',
}, },
{ {
internalType: "bytes32", internalType: 'bytes32',
name: "hash", name: 'hash',
type: "bytes32", type: 'bytes32',
}, },
{ {
internalType: "bytes", internalType: 'bytes',
name: "signature", name: 'signature',
type: "bytes", type: 'bytes',
}, },
], ],
name: "checkSigner", name: 'checkSigner',
outputs: [], outputs: [],
stateMutability: "pure", stateMutability: 'pure',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "signer", name: 'signer',
type: "address", type: 'address',
}, },
{ {
internalType: "bytes32", internalType: 'bytes32',
name: "structHash", name: 'structHash',
type: "bytes32", type: 'bytes32',
}, },
{ {
internalType: "bytes", internalType: 'bytes',
name: "signature", name: 'signature',
type: "bytes", type: 'bytes',
}, },
], ],
name: "checkSigner712", name: 'checkSigner712',
outputs: [], outputs: [],
stateMutability: "view", stateMutability: 'view',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "", name: '',
type: "address", type: 'address',
}, },
], ],
name: "erc20Supported", name: 'erc1155Supported',
outputs: [ outputs: [
{ {
internalType: "bool", internalType: 'bool',
name: "", name: '',
type: "bool", type: 'bool',
}, },
], ],
stateMutability: "view", stateMutability: 'view',
type: "function", 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: [], inputs: [],
name: "executor", name: 'executor',
outputs: [ outputs: [
{ {
internalType: "address", internalType: 'address',
name: "", name: '',
type: "address", type: 'address',
}, },
], ],
stateMutability: "view", stateMutability: 'view',
type: "function", type: 'function',
}, },
{ {
inputs: [], inputs: [],
name: "feeToAddress", name: 'feeToAddress',
outputs: [ outputs: [
{ {
internalType: "address", internalType: 'address',
name: "", name: '',
type: "address", type: 'address',
}, },
], ],
stateMutability: "view", stateMutability: 'view',
type: "function", type: 'function',
}, },
{ {
inputs: [], inputs: [],
name: "getDuration", name: 'getDuration',
outputs: [ outputs: [
{ {
internalType: "uint256", internalType: 'uint256',
name: "duration", name: 'duration',
type: "uint256", type: 'uint256',
}, },
], ],
stateMutability: "view", stateMutability: 'view',
type: "function", type: 'function',
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "nftTokenSupported",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
}, },
{ {
inputs: [], inputs: [],
name: "owner", name: 'owner',
outputs: [ outputs: [
{ {
internalType: "address", internalType: 'address',
name: "", name: '',
type: "address", type: 'address',
}, },
], ],
stateMutability: "view", stateMutability: 'view',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "erc20", name: 'erc20',
type: "address", type: 'address',
}, },
], ],
name: "removeERC20Support", name: 'removeERC20Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [], inputs: [],
name: "renounceOwnership", name: 'renounceOwnership',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "_feeToAddress", name: '_feeToAddress',
type: "address", type: 'address',
}, },
], ],
name: "setFeeToAddress", name: 'setFeeToAddress',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "newOwner", name: 'newOwner',
type: "address", type: 'address',
}, },
], ],
name: "transferOwnership", name: 'transferOwnership',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "uint256", internalType: 'uint256',
name: "valNew", name: 'valNew',
type: "uint256", type: 'uint256',
}, },
], ],
name: "updateDuation", name: 'updateDuation',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "account", name: 'account',
type: "address", type: 'address',
}, },
], ],
name: "updateExecutor", name: 'updateExecutor',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "nftToken", name: 'nftToken',
type: "address", type: 'address',
}, },
], ],
name: "addNFTTokenSupport", name: 'addERC721Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "nftToken", name: 'nftToken',
type: "address", type: 'address',
}, },
], ],
name: "removeNFTTokenSupport", name: 'removeERC721Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address[4]", internalType: 'address',
name: "addresses", name: 'nftToken',
type: "address[4]", type: 'address',
},
{
internalType: "uint256[]",
name: "signArray",
type: "uint256[]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
}, },
], ],
name: "ignoreSignature", name: 'addERC1155Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address[3]", internalType: 'address',
name: "addresses", name: 'nftToken',
type: "address[3]", type: 'address',
},
{
internalType: "uint256[4]",
name: "values",
type: "uint256[4]",
},
{
internalType: "bytes",
name: "signature",
type: "bytes",
}, },
], ],
name: "buyNFT", name: 'removeERC1155Support',
outputs: [], outputs: [],
stateMutability: "nonpayable", stateMutability: 'nonpayable',
type: "function", type: 'function',
}, },
{ {
inputs: [ inputs: [
{ {
internalType: "address", internalType: 'address',
name: "_nftAddress", name: 'currency',
type: "address", type: 'address',
}, },
{ {
internalType: "address", internalType: 'address[]',
name: "_tokenAddress", name: 'nftAddresses',
type: "address", type: 'address[]',
}, },
{ {
internalType: "address", internalType: 'uint256[]',
name: "_buyerAddress", name: 'ids',
type: "address", type: 'uint256[]',
}, },
{ {
internalType: "uint256[]", internalType: 'uint256[]',
name: "_datas", name: 'amounts',
type: "uint256[]", 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: [ outputs: [
{ {
internalType: "bytes32", internalType: 'bytes32',
name: "", name: '',
type: "bytes32", type: 'bytes32',
}, },
], ],
stateMutability: "pure", stateMutability: 'pure',
type: "function", type: 'function',
}, },
]; ];

View File

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

View File

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

View File

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