Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
style improvements for erc1155 basic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hysz committed Mar 7, 2019
1 parent 78ed48c commit 9993097
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 9 additions & 2 deletions contracts/erc1155/contracts/src/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ contract ERC1155 is

// perform transfer
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;
// You could keep balance of NF type in base type id like so:
// uint256 baseType = getNonFungibleBaseType(_id);
Expand Down Expand Up @@ -164,7 +171,7 @@ contract ERC1155 is
nfOwners[id] = to;
} else {
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);
Expand Down
18 changes: 10 additions & 8 deletions contracts/erc1155/test/utils/erc1155_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ export class Erc1155Wrapper {
to: string,
token: BigNumber,
value: BigNumber,
callbackData: string = '0x',
delegatedSpender: string = '',
callbackData?: string,
delegatedSpender?: string,
): 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(
await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackData, {
await this._erc1155Contract.safeTransferFrom.sendTransactionAsync(from, to, token, value, callbackDataHex, {
from: spender,
}),
);
Expand All @@ -49,17 +50,18 @@ export class Erc1155Wrapper {
to: string,
tokens: BigNumber[],
values: BigNumber[],
callbackData: string = '0x',
delegatedSpender: string = '',
callbackData?: string,
delegatedSpender?: string,
): 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(
await this._erc1155Contract.safeBatchTransferFrom.sendTransactionAsync(
from,
to,
tokens,
values,
callbackData,
callbackDataHex,
{ from: spender },
),
);
Expand Down

0 comments on commit 9993097

Please sign in to comment.