style improvements for erc1155 basic implementation
This commit is contained in:
parent
ebfa00d555
commit
07200437b6
@ -77,7 +77,14 @@ contract ERC1155 is
|
|||||||
|
|
||||||
// perform transfer
|
// perform transfer
|
||||||
if (isNonFungible(id)) {
|
if (isNonFungible(id)) {
|
||||||
require(nfOwners[id] == from);
|
require(
|
||||||
|
value == 1,
|
||||||
|
"AMOUNT_EQUAL_TO_ONE_REQUIRED"
|
||||||
|
);
|
||||||
|
require(
|
||||||
|
nfOwners[id] == from,
|
||||||
|
"NFT_NOT_OWNED_BY_FROM_ADDRESS"
|
||||||
|
);
|
||||||
nfOwners[id] = to;
|
nfOwners[id] = to;
|
||||||
// You could keep balance of NF type in base type id like so:
|
// You could keep balance of NF type in base type id like so:
|
||||||
// uint256 baseType = getNonFungibleBaseType(_id);
|
// uint256 baseType = getNonFungibleBaseType(_id);
|
||||||
@ -164,7 +171,7 @@ contract ERC1155 is
|
|||||||
nfOwners[id] = to;
|
nfOwners[id] = to;
|
||||||
} else {
|
} else {
|
||||||
balances[id][from] = safeSub(balances[id][from], value);
|
balances[id][from] = safeSub(balances[id][from], value);
|
||||||
balances[id][to] = safeAdd(value, balances[id][to]);
|
balances[id][to] = safeAdd(balances[id][to], value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit TransferBatch(msg.sender, from, to, ids, values);
|
emit TransferBatch(msg.sender, from, to, ids, values);
|
||||||
|
@ -33,12 +33,13 @@ export class Erc1155Wrapper {
|
|||||||
to: string,
|
to: string,
|
||||||
token: BigNumber,
|
token: BigNumber,
|
||||||
value: BigNumber,
|
value: BigNumber,
|
||||||
callbackData: string = '0x',
|
callbackData?: string,
|
||||||
delegatedSpender: string = '',
|
delegatedSpender?: string,
|
||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender;
|
const spender = _.isUndefined(delegatedSpender) ? from : delegatedSpender;
|
||||||
|
const callbackDataHex = _.isUndefined(callbackData) ? '0x' : callbackData;
|
||||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
|
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
|
||||||
await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackData, {
|
await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackDataHex, {
|
||||||
from: spender,
|
from: spender,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -49,17 +50,18 @@ export class Erc1155Wrapper {
|
|||||||
to: string,
|
to: string,
|
||||||
tokens: BigNumber[],
|
tokens: BigNumber[],
|
||||||
values: BigNumber[],
|
values: BigNumber[],
|
||||||
callbackData: string = '0x',
|
callbackData?: string,
|
||||||
delegatedSpender: string = '',
|
delegatedSpender?: string,
|
||||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const spender = _.isEmpty(delegatedSpender) ? from : delegatedSpender;
|
const spender = _.isUndefined(delegatedSpender) ? from : delegatedSpender;
|
||||||
|
const callbackDataHex = _.isUndefined(callbackData) ? '0x' : callbackData;
|
||||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
|
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(
|
||||||
await this._erc1155Contract.safeBatchTransferFrom.sendTransactionAsync(
|
await this._erc1155Contract.safeBatchTransferFrom.sendTransactionAsync(
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
tokens,
|
tokens,
|
||||||
values,
|
values,
|
||||||
callbackData,
|
callbackDataHex,
|
||||||
{ from: spender },
|
{ from: spender },
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user