-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlandRegistry.sol
1518 lines (1256 loc) · 41.3 KB
/
landRegistry.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
pragma solidity ^0.4.24;
// File: contracts/upgradable/ProxyStorage.sol
contract ProxyStorage {
/**
* Current contract to which we are proxing
*/
address public currentContract;
address public proxyOwner;
}
// File: contracts/upgradable/OwnableStorage.sol
contract OwnableStorage {
address public owner;
constructor() internal {
owner = msg.sender;
}
}
// File: erc821/contracts/AssetRegistryStorage.sol
contract AssetRegistryStorage {
string internal _name;
string internal _symbol;
string internal _description;
/**
* Stores the total count of assets managed by this registry
*/
uint256 internal _count;
/**
* Stores an array of assets owned by a given account
*/
mapping(address => uint256[]) internal _assetsOf;
/**
* Stores the current holder of an asset
*/
mapping(uint256 => address) internal _holderOf;
/**
* Stores the index of an asset in the `_assetsOf` array of its holder
*/
mapping(uint256 => uint256) internal _indexOfAsset;
/**
* Stores the data associated with an asset
*/
mapping(uint256 => string) internal _assetData;
/**
* For a given account, for a given operator, store whether that operator is
* allowed to transfer and modify assets on behalf of them.
*/
mapping(address => mapping(address => bool)) internal _operators;
/**
* Approval array
*/
mapping(uint256 => address) internal _approval;
}
// File: contracts/estate/IEstateRegistry.sol
contract IEstateRegistry {
function mint(address to, string metadata) external returns (uint256);
function ownerOf(uint256 _tokenId) public view returns (address _owner); // from ERC721
// Events
event CreateEstate(
address indexed _owner,
uint256 indexed _estateId,
string _data
);
event AddLand(
uint256 indexed _estateId,
uint256 indexed _landId
);
event RemoveLand(
uint256 indexed _estateId,
uint256 indexed _landId,
address indexed _destinatary
);
event Update(
uint256 indexed _assetId,
address indexed _holder,
address indexed _operator,
string _data
);
event UpdateOperator(
uint256 indexed _estateId,
address indexed _operator
);
event UpdateManager(
address indexed _owner,
address indexed _operator,
address indexed _caller,
bool _approved
);
event SetLANDRegistry(
address indexed _registry
);
event SetEstateLandBalanceToken(
address indexed _previousEstateLandBalance,
address indexed _newEstateLandBalance
);
}
// File: contracts/minimeToken/IMinimeToken.sol
interface IMiniMeToken {
////////////////
// Generate and destroy tokens
////////////////
/// @notice Generates `_amount` tokens that are assigned to `_owner`
/// @param _owner The address that will be assigned the new tokens
/// @param _amount The quantity of tokens generated
/// @return True if the tokens are generated correctly
function generateTokens(address _owner, uint _amount) external returns (bool);
/// @notice Burns `_amount` tokens from `_owner`
/// @param _owner The address that will lose the tokens
/// @param _amount The quantity of tokens to burn
/// @return True if the tokens are burned correctly
function destroyTokens(address _owner, uint _amount) external returns (bool);
/// @param _owner The address that's balance is being requested
/// @return The balance of `_owner` at the current block
function balanceOf(address _owner) external view returns (uint256 balance);
event Transfer(address indexed _from, address indexed _to, uint256 _amount);
}
// File: contracts/land/LANDStorage.sol
contract LANDStorage {
mapping (address => uint) public latestPing;
uint256 constant clearLow = 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000;
uint256 constant clearHigh = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;
uint256 constant factor = 0x100000000000000000000000000000000;
mapping (address => bool) internal _deprecated_authorizedDeploy;
mapping (uint256 => address) public updateOperator;
IEstateRegistry public estateRegistry;
mapping (address => bool) public authorizedDeploy;
mapping(address => mapping(address => bool)) public updateManager;
// Land balance minime token
IMiniMeToken public landBalance;
// Registered balance accounts
mapping(address => bool) public registeredBalance;
}
// File: contracts/Storage.sol
contract Storage is ProxyStorage, OwnableStorage, AssetRegistryStorage, LANDStorage {
}
// File: contracts/upgradable/Ownable.sol
contract Ownable is Storage {
event OwnerUpdate(address _prevOwner, address _newOwner);
modifier onlyOwner {
assert(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != owner, "Cannot transfer to yourself");
owner = _newOwner;
}
}
// File: contracts/upgradable/IApplication.sol
contract IApplication {
function initialize(bytes data) public;
}
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
c = _a * _b;
assert(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
// assert(_b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return _a / _b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
assert(_b <= _a);
return _a - _b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
c = _a + _b;
assert(c >= _a);
return c;
}
}
// File: erc821/contracts/IERC721Base.sol
interface IERC721Base {
function totalSupply() external view returns (uint256);
// function exists(uint256 assetId) external view returns (bool);
function ownerOf(uint256 assetId) external view returns (address);
function balanceOf(address holder) external view returns (uint256);
function safeTransferFrom(address from, address to, uint256 assetId) external;
function safeTransferFrom(address from, address to, uint256 assetId, bytes userData) external;
function transferFrom(address from, address to, uint256 assetId) external;
function approve(address operator, uint256 assetId) external;
function setApprovalForAll(address operator, bool authorized) external;
function getApprovedAddress(uint256 assetId) external view returns (address);
function isApprovedForAll(address assetHolder, address operator) external view returns (bool);
function isAuthorized(address operator, uint256 assetId) external view returns (bool);
/**
* @dev Deprecated transfer event. Now we use the standard with three parameters
* It is only used in the ABI to get old transfer events. Do not remove
*/
event Transfer(
address indexed from,
address indexed to,
uint256 indexed assetId,
address operator,
bytes userData,
bytes operatorData
);
/**
* @dev Deprecated transfer event. Now we use the standard with three parameters
* It is only used in the ABI to get old transfer events. Do not remove
*/
event Transfer(
address indexed from,
address indexed to,
uint256 indexed assetId,
address operator,
bytes userData
);
event Transfer(
address indexed from,
address indexed to,
uint256 indexed assetId
);
event ApprovalForAll(
address indexed holder,
address indexed operator,
bool authorized
);
event Approval(
address indexed owner,
address indexed operator,
uint256 indexed assetId
);
}
// File: erc821/contracts/IERC721Receiver.sol
interface IERC721Receiver {
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes _userData
) external returns (bytes4);
}
// File: erc821/contracts/ERC165.sol
interface ERC165 {
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
// File: erc821/contracts/ERC721Base.sol
contract ERC721Base is AssetRegistryStorage, IERC721Base, ERC165 {
using SafeMath for uint256;
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
bytes4 private constant ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant InterfaceId_ERC165 = 0x01ffc9a7;
/*
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant Old_InterfaceId_ERC721 = 0x7c0633c6;
bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
//
// Global Getters
//
/**
* @dev Gets the total amount of assets stored by the contract
* @return uint256 representing the total amount of assets
*/
function totalSupply() external view returns (uint256) {
return _totalSupply();
}
function _totalSupply() internal view returns (uint256) {
return _count;
}
//
// Asset-centric getter functions
//
/**
* @dev Queries what address owns an asset. This method does not throw.
* In order to check if the asset exists, use the `exists` function or check if the
* return value of this call is `0`.
* @return uint256 the assetId
*/
function ownerOf(uint256 assetId) external view returns (address) {
return _ownerOf(assetId);
}
function _ownerOf(uint256 assetId) internal view returns (address) {
return _holderOf[assetId];
}
//
// Holder-centric getter functions
//
/**
* @dev Gets the balance of the specified address
* @param owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address owner) external view returns (uint256) {
return _balanceOf(owner);
}
function _balanceOf(address owner) internal view returns (uint256) {
return _assetsOf[owner].length;
}
//
// Authorization getters
//
/**
* @dev Query whether an address has been authorized to move any assets on behalf of someone else
* @param operator the address that might be authorized
* @param assetHolder the address that provided the authorization
* @return bool true if the operator has been authorized to move any assets
*/
function isApprovedForAll(address assetHolder, address operator)
external view returns (bool)
{
return _isApprovedForAll(assetHolder, operator);
}
function _isApprovedForAll(address assetHolder, address operator)
internal view returns (bool)
{
return _operators[assetHolder][operator];
}
/**
* @dev Query what address has been particularly authorized to move an asset
* @param assetId the asset to be queried for
* @return bool true if the asset has been approved by the holder
*/
function getApproved(uint256 assetId) external view returns (address) {
return _getApprovedAddress(assetId);
}
function getApprovedAddress(uint256 assetId) external view returns (address) {
return _getApprovedAddress(assetId);
}
function _getApprovedAddress(uint256 assetId) internal view returns (address) {
return _approval[assetId];
}
/**
* @dev Query if an operator can move an asset.
* @param operator the address that might be authorized
* @param assetId the asset that has been `approved` for transfer
* @return bool true if the asset has been approved by the holder
*/
function isAuthorized(address operator, uint256 assetId) external view returns (bool) {
return _isAuthorized(operator, assetId);
}
function _isAuthorized(address operator, uint256 assetId) internal view returns (bool)
{
require(operator != 0);
address owner = _ownerOf(assetId);
if (operator == owner) {
return true;
}
return _isApprovedForAll(owner, operator) || _getApprovedAddress(assetId) == operator;
}
//
// Authorization
//
/**
* @dev Authorize a third party operator to manage (send) msg.sender's asset
* @param operator address to be approved
* @param authorized bool set to true to authorize, false to withdraw authorization
*/
function setApprovalForAll(address operator, bool authorized) external {
return _setApprovalForAll(operator, authorized);
}
function _setApprovalForAll(address operator, bool authorized) internal {
if (authorized) {
require(!_isApprovedForAll(msg.sender, operator));
_addAuthorization(operator, msg.sender);
} else {
require(_isApprovedForAll(msg.sender, operator));
_clearAuthorization(operator, msg.sender);
}
emit ApprovalForAll(msg.sender, operator, authorized);
}
/**
* @dev Authorize a third party operator to manage one particular asset
* @param operator address to be approved
* @param assetId asset to approve
*/
function approve(address operator, uint256 assetId) external {
address holder = _ownerOf(assetId);
require(msg.sender == holder || _isApprovedForAll(msg.sender, holder));
require(operator != holder);
if (_getApprovedAddress(assetId) != operator) {
_approval[assetId] = operator;
emit Approval(holder, operator, assetId);
}
}
function _addAuthorization(address operator, address holder) private {
_operators[holder][operator] = true;
}
function _clearAuthorization(address operator, address holder) private {
_operators[holder][operator] = false;
}
//
// Internal Operations
//
function _addAssetTo(address to, uint256 assetId) internal {
_holderOf[assetId] = to;
uint256 length = _balanceOf(to);
_assetsOf[to].push(assetId);
_indexOfAsset[assetId] = length;
_count = _count.add(1);
}
function _removeAssetFrom(address from, uint256 assetId) internal {
uint256 assetIndex = _indexOfAsset[assetId];
uint256 lastAssetIndex = _balanceOf(from).sub(1);
uint256 lastAssetId = _assetsOf[from][lastAssetIndex];
_holderOf[assetId] = 0;
// Insert the last asset into the position previously occupied by the asset to be removed
_assetsOf[from][assetIndex] = lastAssetId;
// Resize the array
_assetsOf[from][lastAssetIndex] = 0;
_assetsOf[from].length--;
// Remove the array if no more assets are owned to prevent pollution
if (_assetsOf[from].length == 0) {
delete _assetsOf[from];
}
// Update the index of positions for the asset
_indexOfAsset[assetId] = 0;
_indexOfAsset[lastAssetId] = assetIndex;
_count = _count.sub(1);
}
function _clearApproval(address holder, uint256 assetId) internal {
if (_ownerOf(assetId) == holder && _approval[assetId] != 0) {
_approval[assetId] = 0;
emit Approval(holder, 0, assetId);
}
}
//
// Supply-altering functions
//
function _generate(uint256 assetId, address beneficiary) internal {
require(_holderOf[assetId] == 0);
_addAssetTo(beneficiary, assetId);
emit Transfer(0, beneficiary, assetId);
}
function _destroy(uint256 assetId) internal {
address holder = _holderOf[assetId];
require(holder != 0);
_removeAssetFrom(holder, assetId);
emit Transfer(holder, 0, assetId);
}
//
// Transaction related operations
//
modifier onlyHolder(uint256 assetId) {
require(_ownerOf(assetId) == msg.sender);
_;
}
modifier onlyAuthorized(uint256 assetId) {
require(_isAuthorized(msg.sender, assetId));
_;
}
modifier isCurrentOwner(address from, uint256 assetId) {
require(_ownerOf(assetId) == from);
_;
}
modifier isDestinataryDefined(address destinatary) {
require(destinatary != 0);
_;
}
modifier destinataryIsNotHolder(uint256 assetId, address to) {
require(_ownerOf(assetId) != to);
_;
}
/**
* @dev Alias of `safeTransferFrom(from, to, assetId, '')`
*
* @param from address that currently owns an asset
* @param to address to receive the ownership of the asset
* @param assetId uint256 ID of the asset to be transferred
*/
function safeTransferFrom(address from, address to, uint256 assetId) external {
return _doTransferFrom(from, to, assetId, '', true);
}
/**
* @dev Securely transfers the ownership of a given asset from one address to
* another address, calling the method `onNFTReceived` on the target address if
* there's code associated with it
*
* @param from address that currently owns an asset
* @param to address to receive the ownership of the asset
* @param assetId uint256 ID of the asset to be transferred
* @param userData bytes arbitrary user information to attach to this transfer
*/
function safeTransferFrom(address from, address to, uint256 assetId, bytes userData) external {
return _doTransferFrom(from, to, assetId, userData, true);
}
/**
* @dev Transfers the ownership of a given asset from one address to another address
* Warning! This function does not attempt to verify that the target address can send
* tokens.
*
* @param from address sending the asset
* @param to address to receive the ownership of the asset
* @param assetId uint256 ID of the asset to be transferred
*/
function transferFrom(address from, address to, uint256 assetId) external {
return _doTransferFrom(from, to, assetId, '', false);
}
function _doTransferFrom(
address from,
address to,
uint256 assetId,
bytes userData,
bool doCheck
)
onlyAuthorized(assetId)
internal
{
_moveToken(from, to, assetId, userData, doCheck);
}
function _moveToken(
address from,
address to,
uint256 assetId,
bytes userData,
bool doCheck
)
isDestinataryDefined(to)
destinataryIsNotHolder(assetId, to)
isCurrentOwner(from, assetId)
private
{
address holder = _holderOf[assetId];
_clearApproval(holder, assetId);
_removeAssetFrom(holder, assetId);
_addAssetTo(to, assetId);
emit Transfer(holder, to, assetId);
if (doCheck && _isContract(to)) {
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))
require(
IERC721Receiver(to).onERC721Received(
msg.sender, holder, assetId, userData
) == ERC721_RECEIVED
);
}
}
/**
* Internal function that moves an asset from one holder to another
*/
/**
* @dev Returns `true` if the contract implements `interfaceID` and `interfaceID` is not 0xffffffff, `false` otherwise
* @param _interfaceID The interface identifier, as specified in ERC-165
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == 0xffffffff) {
return false;
}
return _interfaceID == InterfaceId_ERC165 || _interfaceID == Old_InterfaceId_ERC721 || _interfaceID == InterfaceId_ERC721;
}
//
// Utilities
//
function _isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}
// File: erc821/contracts/IERC721Enumerable.sol
contract IERC721Enumerable {
/**
* @notice Enumerate active tokens
* @dev Throws if `index` >= `totalSupply()`, otherwise SHALL NOT throw.
* @param index A counter less than `totalSupply()`
* @return The identifier for the `index`th asset, (sort order not
* specified)
*/
// TODO (eordano): Not implemented
// function tokenByIndex(uint256 index) public view returns (uint256 _assetId);
/**
* @notice Count of owners which own at least one asset
* Must not throw.
* @return A count of the number of owners which own asset
*/
// TODO (eordano): Not implemented
// function countOfOwners() public view returns (uint256 _count);
/**
* @notice Enumerate owners
* @dev Throws if `index` >= `countOfOwners()`, otherwise must not throw.
* @param index A counter less than `countOfOwners()`
* @return The address of the `index`th owner (sort order not specified)
*/
// TODO (eordano): Not implemented
// function ownerByIndex(uint256 index) public view returns (address owner);
/**
* @notice Get all tokens of a given address
* @dev This is not intended to be used on-chain
* @param owner address of the owner to query
* @return a list of all assetIds of a user
*/
function tokensOf(address owner) external view returns (uint256[]);
/**
* @notice Enumerate tokens assigned to an owner
* @dev Throws if `index` >= `balanceOf(owner)` or if
* `owner` is the zero address, representing invalid assets.
* Otherwise this must not throw.
* @param owner An address where we are interested in assets owned by them
* @param index A counter less than `balanceOf(owner)`
* @return The identifier for the `index`th asset assigned to `owner`,
* (sort order not specified)
*/
function tokenOfOwnerByIndex(
address owner, uint256 index
) external view returns (uint256 tokenId);
}
// File: erc821/contracts/ERC721Enumerable.sol
contract ERC721Enumerable is AssetRegistryStorage, IERC721Enumerable {
/**
* @notice Get all tokens of a given address
* @dev This is not intended to be used on-chain
* @param owner address of the owner to query
* @return a list of all assetIds of a user
*/
function tokensOf(address owner) external view returns (uint256[]) {
return _assetsOf[owner];
}
/**
* @notice Enumerate tokens assigned to an owner
* @dev Throws if `index` >= `balanceOf(owner)` or if
* `owner` is the zero address, representing invalid assets.
* Otherwise this must not throw.
* @param owner An address where we are interested in assets owned by them
* @param index A counter less than `balanceOf(owner)`
* @return The identifier for the `index`th asset assigned to `owner`,
* (sort order not specified)
*/
function tokenOfOwnerByIndex(
address owner, uint256 index
)
external
view
returns (uint256 assetId)
{
require(index < _assetsOf[owner].length);
require(index < (1<<127));
return _assetsOf[owner][index];
}
}
// File: erc821/contracts/IERC721Metadata.sol
contract IERC721Metadata {
/**
* @notice A descriptive name for a collection of NFTs in this contract
*/
function name() external view returns (string);
/**
* @notice An abbreviated name for NFTs in this contract
*/
function symbol() external view returns (string);
/**
* @notice A description of what this DAR is used for
*/
function description() external view returns (string);
/**
* Stores arbitrary info about a token
*/
function tokenMetadata(uint256 assetId) external view returns (string);
}
// File: erc821/contracts/ERC721Metadata.sol
contract ERC721Metadata is AssetRegistryStorage, IERC721Metadata {
function name() external view returns (string) {
return _name;
}
function symbol() external view returns (string) {
return _symbol;
}
function description() external view returns (string) {
return _description;
}
function tokenMetadata(uint256 assetId) external view returns (string) {
return _assetData[assetId];
}
function _update(uint256 assetId, string data) internal {
_assetData[assetId] = data;
}
}
// File: erc821/contracts/FullAssetRegistry.sol
contract FullAssetRegistry is ERC721Base, ERC721Enumerable, ERC721Metadata {
constructor() public {
}
/**
* @dev Method to check if an asset identified by the given id exists under this DAR.
* @return uint256 the assetId
*/
function exists(uint256 assetId) external view returns (bool) {
return _exists(assetId);
}
function _exists(uint256 assetId) internal view returns (bool) {
return _holderOf[assetId] != 0;
}
function decimals() external pure returns (uint256) {
return 0;
}
}
// File: contracts/land/ILANDRegistry.sol
interface ILANDRegistry {
// LAND can be assigned by the owner
function assignNewParcel(int x, int y, address beneficiary) external;
function assignMultipleParcels(int[] x, int[] y, address beneficiary) external;
// After one year, LAND can be claimed from an inactive public key
function ping() external;
// LAND-centric getters
function encodeTokenId(int x, int y) external pure returns (uint256);
function decodeTokenId(uint value) external pure returns (int, int);
function exists(int x, int y) external view returns (bool);
function ownerOfLand(int x, int y) external view returns (address);
function ownerOfLandMany(int[] x, int[] y) external view returns (address[]);
function landOf(address owner) external view returns (int[], int[]);
function landData(int x, int y) external view returns (string);
// Transfer LAND
function transferLand(int x, int y, address to) external;
function transferManyLand(int[] x, int[] y, address to) external;
// Update LAND
function updateLandData(int x, int y, string data) external;
function updateManyLandData(int[] x, int[] y, string data) external;
// Authorize an updateManager to manage parcel data
function setUpdateManager(address _owner, address _operator, bool _approved) external;
// Events
event Update(
uint256 indexed assetId,
address indexed holder,
address indexed operator,
string data
);
event UpdateOperator(
uint256 indexed assetId,
address indexed operator
);
event UpdateManager(
address indexed _owner,
address indexed _operator,
address indexed _caller,
bool _approved
);
event DeployAuthorized(
address indexed _caller,
address indexed _deployer
);
event DeployForbidden(
address indexed _caller,
address indexed _deployer
);
event SetLandBalanceToken(
address indexed _previousLandBalance,
address indexed _newLandBalance
);
}
// File: contracts/metadata/IMetadataHolder.sol
contract IMetadataHolder is ERC165 {
function getMetadata(uint256 /* assetId */) external view returns (string);
}
// File: contracts/land/LANDRegistry.sol
/* solium-disable function-order */
contract LANDRegistry is Storage, Ownable, FullAssetRegistry, ILANDRegistry {
bytes4 constant public GET_METADATA = bytes4(keccak256("getMetadata(uint256)"));
function initialize(bytes) external {
_name = "Bearland LAND";
_symbol = "LAND";
_description = "Contract that stores the Bearland LAND registry";
}
modifier onlyProxyOwner() {
require(msg.sender == proxyOwner, "This function can only be called by the proxy owner");
_;
}
modifier onlyDeployer() {
require(
msg.sender == proxyOwner || authorizedDeploy[msg.sender],
"This function can only be called by an authorized deployer"
);
_;
}
modifier onlyOwnerOf(uint256 assetId) {
require(
msg.sender == _ownerOf(assetId),
"This function can only be called by the owner of the asset"
);
_;
}
modifier onlyUpdateAuthorized(uint256 tokenId) {
require(
msg.sender == _ownerOf(tokenId) ||
_isAuthorized(msg.sender, tokenId) ||
_isUpdateAuthorized(msg.sender, tokenId),
"msg.sender is not authorized to update"
);
_;
}
modifier canSetUpdateOperator(uint256 tokenId) {
address owner = _ownerOf(tokenId);
require(
_isAuthorized(msg.sender, tokenId) || updateManager[owner][msg.sender],