commit af1e051c6691c07db854228e309dccd55c0e6ea2
parent 7401df4734854b16c75c2dd999f82404bda99ddb
Author: nolash <dev@holbrook.no>
Date: Sat, 8 May 2021 08:37:48 +0200
Separate out EIP721 interface, add EIP173 support
Diffstat:
12 files changed, 331 insertions(+), 253 deletions(-)
diff --git a/python/eth_badge/data/BadgeToken.bin b/python/eth_badge/data/BadgeToken.bin
@@ -0,0 +1 @@
+60806040523480156200001157600080fd5b50604051620028113803806200281183398181016040528101906200003791906200022c565b82600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600c9080519060200190620000d0929190620000f3565b5080600d9080519060200190620000e9929190620000f3565b5050505062000472565b82805462000101906200037d565b90600052602060002090601f01602090048101928262000125576000855562000171565b82601f106200014057805160ff191683800117855562000171565b8280016001018555821562000171579182015b828111156200017057825182559160200191906001019062000153565b5b50905062000180919062000184565b5090565b5b808211156200019f57600081600090555060010162000185565b5090565b6000620001ba620001b484620002dd565b620002b4565b905082815260208101848484011115620001d357600080fd5b620001e084828562000347565b509392505050565b600081519050620001f98162000458565b92915050565b600082601f8301126200021157600080fd5b815162000223848260208601620001a3565b91505092915050565b6000806000606084860312156200024257600080fd5b60006200025286828701620001e8565b935050602084015167ffffffffffffffff8111156200027057600080fd5b6200027e86828701620001ff565b925050604084015167ffffffffffffffff8111156200029c57600080fd5b620002aa86828701620001ff565b9150509250925092565b6000620002c0620002d3565b9050620002ce8282620003b3565b919050565b6000604051905090565b600067ffffffffffffffff821115620002fb57620002fa62000418565b5b620003068262000447565b9050602081019050919050565b6000620003208262000327565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60005b83811015620003675780820151818401526020810190506200034a565b8381111562000377576000848401525b50505050565b600060028204905060018216806200039657607f821691505b60208210811415620003ad57620003ac620003e9565b5b50919050565b620003be8262000447565b810181811067ffffffffffffffff82111715620003e057620003df62000418565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b620004638162000313565b81146200046f57600080fd5b50565b61238f80620004826000396000f3fe60806040526004361061013c576000357c0100000000000000000000000000000000000000000000000000000000900480636352211e116100bd578063a22cb46511610081578063a22cb46514610417578063b88d4fde14610440578063e985e9c51461045c578063f1b0aa1514610499578063f2fde38b146104d65761013c565b80636352211e1461031c57806370a08231146103595780638da5cb5b1461039657806392088cf6146103c157806395d89b41146103ec5761013c565b806323b872dd1161010457806323b872dd1461022d5780632f745c591461024957806342842e0e14610286578063449a52f8146102a25780634f6ccce7146102df5761013c565b806301ffc9a71461014157806306fdde031461017e578063081812fc146101a9578063095ea7b3146101e657806318160ddd14610202575b600080fd5b34801561014d57600080fd5b5061016860048036038101906101639190611e6e565b610513565b6040516101759190611f50565b60405180910390f35b34801561018a57600080fd5b506101936106be565b6040516101a09190611f86565b60405180910390f35b3480156101b557600080fd5b506101d060048036038101906101cb9190611e97565b61074c565b6040516101dd9190611f35565b60405180910390f35b61020060048036038101906101fb9190611e32565b610789565b005b34801561020e57600080fd5b506102176108a5565b6040516102249190611fa8565b60405180910390f35b61024760048036038101906102429190611d2c565b6108b2565b005b34801561025557600080fd5b50610270600480360381019061026b9190611e32565b610921565b60405161027d9190611fa8565b60405180910390f35b6102a0600480360381019061029b9190611d2c565b6109f8565b005b3480156102ae57600080fd5b506102c960048036038101906102c49190611e32565b610a67565b6040516102d69190611f50565b60405180910390f35b3480156102eb57600080fd5b5061030660048036038101906103019190611e97565b610d29565b6040516103139190611fa8565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e9190611e97565b610d77565b6040516103509190611f35565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b9190611cc7565b610db4565b60405161038d9190611fa8565b60405180910390f35b3480156103a257600080fd5b506103ab610dfd565b6040516103b89190611f35565b60405180910390f35b3480156103cd57600080fd5b506103d6610e21565b6040516103e39190611f35565b60405180910390f35b3480156103f857600080fd5b50610401610e47565b60405161040e9190611f86565b60405180910390f35b34801561042357600080fd5b5061043e60048036038101906104399190611df6565b610ed5565b005b61045a60048036038101906104559190611d7b565b611178565b005b34801561046857600080fd5b50610483600480360381019061047e9190611cf0565b6112c2565b6040516104909190611f50565b60405180910390f35b3480156104a557600080fd5b506104c060048036038101906104bb9190611e97565b61135a565b6040516104cd9190611fa8565b60405180910390f35b3480156104e257600080fd5b506104fd60048036038101906104f89190611cc7565b6113c0565b60405161050a9190611f50565b60405180910390f35b60006380ac58cd7c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561056857600190506106b9565b635b5e139f7c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156105bb57600190506106b9565b63780e9d637c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561060e57600190506106b9565b63449a52f87c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561066157600190506106b9565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156106b457600190506106b9565b600090505b919050565b600c80546106cb90612153565b80601f01602080910402602001604051908101604052809291908181526020018280546106f790612153565b80156107445780601f1061071957610100808354040283529160200191610744565b820191906000526020600020905b81548152906001019060200180831161072757829003601f168201915b505050505081565b60006009600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b3373ffffffffffffffffffffffffffffffffffffffff166005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146107f457600080fd5b816009600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000600280549050905090565b60606108c0848484846115e6565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450505050565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821061096e57600080fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106109e5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154905092915050565b6060610a06848484846115e6565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450505050565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610ac157600080fd5b600060046000848152602001908152602001600020541480610ae857506000600280549050145b610af157600080fd5b600080600280549050915083905060028190806001815401808255809150506001900390600052602060002001600090919091909150556003439080600181540180825580915050600190039060005260206000200160009091909190915055846005600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360076000600660008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080549050815260200190815260200160002081905550600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020849080600181540180825580915050600190039060005260206000200160009091909190915055600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190610cb3906121b6565b91905055508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f886604051610d159190611fa8565b60405180910390a360019250505092915050565b600060028281548110610d65577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b60006005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600d8054610e5490612153565b80601f0160208091040260200160405190810160405280929190818152602001828054610e8090612153565b8015610ecd5780601f10610ea257610100808354040283529160200191610ecd565b820191906000526020600020905b815481529060010190602001808311610eb057829003601f168201915b505050505081565b8015610ff657600073ffffffffffffffffffffffffffffffffffffffff16600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f7357600080fd5b81600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061110f565b600073ffffffffffffffffffffffffffffffffffffffff16600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561108f57600080fd5b6000600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405161116c9190611f50565b60405180910390a35050565b611184848484846115e6565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f75c9e114f073c346aac7d1d7e9a3c3c14edabcdd27de07d1d9e425f45d318c5e600b60008781526020019081526020016000206001600b6000898152602001908152602001600020805490506112659190612035565b8154811061129c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001546040516112b49190611f6b565b60405180910390a450505050565b60008173ffffffffffffffffffffffffffffffffffffffff16600a60008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614905092915050565b60008060046000848152602001908152602001600020549050600381815481106113ad577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154915050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461141b57600080fd5b60606000606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff169150600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156114cd57602002820191906000526020600020905b8154815260200190600101908083116114b9575b5050505050905060005b815181101561153f5761152c838784848151811061151e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151876115e6565b8080611537906121b6565b9150506114d7565b50846000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508473ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360019350505050919050565b60006005600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508473ffffffffffffffffffffffffffffffffffffffff166005600085815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461168957600080fd5b3373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16146117bd573373ffffffffffffffffffffffffffffffffffffffff166009600085815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614806117b357503373ffffffffffffffffffffffffffffffffffffffff16600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b6117bc57600080fd5b5b60006009600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001600660008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905061189e9190612035565b815481106118d5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060076000868152602001908152602001600020548154811061196a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200181905550600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008154809291906119c890612129565b9190505550600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020839080600181540180825580915050600190039060005260206000200160009091909190915055600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190611a83906121b6565b9190505550836005600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060005b8251811015611c0357828181518110611b1f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916600b6000868152602001908152602001600020602083611bab91906121ff565b81548110611be2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001819055508080611bfb906121b6565b915050611add565b505050505050565b6000611c1e611c1984611fe8565b611fc3565b905082815260208101848484011115611c3657600080fd5b611c418482856120e7565b509392505050565b600081359050611c58816122fd565b92915050565b600081359050611c6d81612314565b92915050565b600081359050611c828161232b565b92915050565b600082601f830112611c9957600080fd5b8135611ca9848260208601611c0b565b91505092915050565b600081359050611cc181612342565b92915050565b600060208284031215611cd957600080fd5b6000611ce784828501611c49565b91505092915050565b60008060408385031215611d0357600080fd5b6000611d1185828601611c49565b9250506020611d2285828601611c49565b9150509250929050565b600080600060608486031215611d4157600080fd5b6000611d4f86828701611c49565b9350506020611d6086828701611c49565b9250506040611d7186828701611cb2565b9150509250925092565b60008060008060808587031215611d9157600080fd5b6000611d9f87828801611c49565b9450506020611db087828801611c49565b9350506040611dc187828801611cb2565b925050606085013567ffffffffffffffff811115611dde57600080fd5b611dea87828801611c88565b91505092959194509250565b60008060408385031215611e0957600080fd5b6000611e1785828601611c49565b9250506020611e2885828601611c5e565b9150509250929050565b60008060408385031215611e4557600080fd5b6000611e5385828601611c49565b9250506020611e6485828601611cb2565b9150509250929050565b600060208284031215611e8057600080fd5b6000611e8e84828501611c73565b91505092915050565b600060208284031215611ea957600080fd5b6000611eb784828501611cb2565b91505092915050565b611ec981612069565b82525050565b611ed88161207b565b82525050565b611ee781612087565b82525050565b6000611ef882612019565b611f028185612024565b9350611f128185602086016120f6565b611f1b816122ec565b840191505092915050565b611f2f816120dd565b82525050565b6000602082019050611f4a6000830184611ec0565b92915050565b6000602082019050611f656000830184611ecf565b92915050565b6000602082019050611f806000830184611ede565b92915050565b60006020820190508181036000830152611fa08184611eed565b905092915050565b6000602082019050611fbd6000830184611f26565b92915050565b6000611fcd611fde565b9050611fd98282612185565b919050565b6000604051905090565b600067ffffffffffffffff821115612003576120026122bd565b5b61200c826122ec565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b6000612040826120dd565b915061204b836120dd565b92508282101561205e5761205d612230565b5b828203905092915050565b6000612074826120bd565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b838110156121145780820151818401526020810190506120f9565b83811115612123576000848401525b50505050565b6000612134826120dd565b9150600082141561214857612147612230565b5b600182039050919050565b6000600282049050600182168061216b57607f821691505b6020821081141561217f5761217e61228e565b5b50919050565b61218e826122ec565b810181811067ffffffffffffffff821117156121ad576121ac6122bd565b5b80604052505050565b60006121c1826120dd565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156121f4576121f3612230565b5b600182019050919050565b600061220a826120dd565b9150612215836120dd565b9250826122255761222461225f565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b61230681612069565b811461231157600080fd5b50565b61231d8161207b565b811461232857600080fd5b50565b61233481612091565b811461233f57600080fd5b50565b61234b816120dd565b811461235657600080fd5b5056fea26469706673582212203192308cf5bb460567ed09c15b7e3f3aac5a9f3acd7511e0b579ca56fffd9c1b64736f6c63430008030033
+\ No newline at end of file
diff --git a/python/eth_badge/data/BadgeToken.json b/python/eth_badge/data/BadgeToken.json
@@ -0,0 +1 @@
+[{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_operator","type":"address"},{"indexed":false,"internalType":"bool","name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Mint","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":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"_data","type":"bytes32"}],"name":"TransferWithData","type":"event"},{"inputs":[{"internalType":"address","name":"_approved","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"declarator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_beneficiary","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"mintedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"bool","name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
diff --git a/python/eth_badge/token.py b/python/eth_badge/token.py
@@ -0,0 +1,99 @@
+# standard imports
+import os
+
+# external imports
+from chainlib.eth.tx import (
+ TxFormat,
+ TxFactory,
+ )
+from chainlib.eth.contract import (
+ ABIContractEncoder,
+ ABIContractType,
+ abi_decode_single,
+ )
+from chainlib.jsonrpc import jsonrpc_template
+from chainlib.eth.constant import ZERO_ADDRESS
+from hexathon import (
+ add_0x,
+ )
+
+# local imports
+from eth_erc721 import ERC721
+
+moddir = os.path.dirname(__file__)
+datadir = os.path.join(moddir, 'data')
+
+
+class BadgeToken(ERC721):
+
+ __abi = None
+ __bytecode = None
+
+ @staticmethod
+ def abi():
+ if BadgeToken.__abi == None:
+ f = open(os.path.join(datadir, 'BadgeToken.json'), 'r')
+ BadgeToken.__abi = json.load(f)
+ f.close()
+ return BadgeToken.__abi
+
+
+ @staticmethod
+ def bytecode():
+ if BadgeToken.__bytecode == None:
+ f = open(os.path.join(datadir, 'BadgeToken.bin'))
+ BadgeToken.__bytecode = f.read()
+ f.close()
+ return BadgeToken.__bytecode
+
+
+ @staticmethod
+ def gas(code=None):
+ return 1200000
+
+
+ def constructor(self, sender_address, declarator, name, symbol, tx_format=TxFormat.JSONRPC):
+ code = BadgeToken.bytecode()
+ enc = ABIContractEncoder()
+ enc.address(declarator)
+ enc.string(name)
+ enc.string(symbol)
+ code += enc.get()
+ tx = self.template(sender_address, None, use_nonce=True)
+ tx = self.set_code(tx, code)
+ return self.finalize(tx, tx_format)
+
+
+ def mint_to(self, contract_address, sender_address, address, token_id, tx_format=TxFormat.JSONRPC):
+ enc = ABIContractEncoder()
+ enc.method('mintTo')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.typ(ABIContractType.UINT256)
+ enc.address(address)
+ enc.uint256(token_id)
+ data = enc.get()
+ tx = self.template(sender_address, contract_address, use_nonce=True)
+ tx = self.set_code(tx, data)
+ tx = self.finalize(tx, tx_format)
+ return tx
+
+
+
+ def minted_at(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('mintedAt')
+ enc.typ(ABIContractType.UINT256)
+ enc.uint256(token_id)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+ @classmethod
+ def parse_minted_at(self, v):
+ return abi_decode_single(ABIContractType.UINT256, v)
diff --git a/python/eth_devbadge/data/BadgeToken.bin b/python/eth_devbadge/data/BadgeToken.bin
@@ -1 +0,0 @@
-60806040523480156200001157600080fd5b50604051620025a5380380620025a583398181016040528101906200003791906200022c565b826000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600c9080519060200190620000d0929190620000f3565b5080600d9080519060200190620000e9929190620000f3565b5050505062000472565b82805462000101906200037d565b90600052602060002090601f01602090048101928262000125576000855562000171565b82601f106200014057805160ff191683800117855562000171565b8280016001018555821562000171579182015b828111156200017057825182559160200191906001019062000153565b5b50905062000180919062000184565b5090565b5b808211156200019f57600081600090555060010162000185565b5090565b6000620001ba620001b484620002dd565b620002b4565b905082815260208101848484011115620001d357600080fd5b620001e084828562000347565b509392505050565b600081519050620001f98162000458565b92915050565b600082601f8301126200021157600080fd5b815162000223848260208601620001a3565b91505092915050565b6000806000606084860312156200024257600080fd5b60006200025286828701620001e8565b935050602084015167ffffffffffffffff8111156200027057600080fd5b6200027e86828701620001ff565b925050604084015167ffffffffffffffff8111156200029c57600080fd5b620002aa86828701620001ff565b9150509250925092565b6000620002c0620002d3565b9050620002ce8282620003b3565b919050565b6000604051905090565b600067ffffffffffffffff821115620002fb57620002fa62000418565b5b620003068262000447565b9050602081019050919050565b6000620003208262000327565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60005b83811015620003675780820151818401526020810190506200034a565b8381111562000377576000848401525b50505050565b600060028204905060018216806200039657607f821691505b60208210811415620003ad57620003ac620003e9565b5b50919050565b620003be8262000447565b810181811067ffffffffffffffff82111715620003e057620003df62000418565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b620004638162000313565b81146200046f57600080fd5b50565b61212380620004826000396000f3fe608060405260043610610131576000357c0100000000000000000000000000000000000000000000000000000000900480634f6ccce7116100bd57806395d89b411161008157806395d89b41146103e1578063a22cb4651461040c578063b88d4fde14610435578063e985e9c514610451578063f1b0aa151461048e57610131565b80634f6ccce7146102d45780636352211e1461031157806370a082311461034e5780638da5cb5b1461038b57806392088cf6146103b657610131565b806318160ddd1161010457806318160ddd146101f757806323b872dd146102225780632f745c591461023e57806342842e0e1461027b578063449a52f81461029757610131565b806301ffc9a71461013657806306fdde0314610173578063081812fc1461019e578063095ea7b3146101db575b600080fd5b34801561014257600080fd5b5061015d60048036038101906101589190611c02565b6104cb565b60405161016a9190611ce4565b60405180910390f35b34801561017f57600080fd5b50610188610676565b6040516101959190611d1a565b60405180910390f35b3480156101aa57600080fd5b506101c560048036038101906101c09190611c2b565b610704565b6040516101d29190611cc9565b60405180910390f35b6101f560048036038101906101f09190611bc6565b610741565b005b34801561020357600080fd5b5061020c61085d565b6040516102199190611d3c565b60405180910390f35b61023c60048036038101906102379190611ac0565b61086a565b005b34801561024a57600080fd5b5061026560048036038101906102609190611bc6565b6108d9565b6040516102729190611d3c565b60405180910390f35b61029560048036038101906102909190611ac0565b6109b0565b005b3480156102a357600080fd5b506102be60048036038101906102b99190611bc6565b610a1f565b6040516102cb9190611ce4565b60405180910390f35b3480156102e057600080fd5b506102fb60048036038101906102f69190611c2b565b610ce3565b6040516103089190611d3c565b60405180910390f35b34801561031d57600080fd5b5061033860048036038101906103339190611c2b565b610d31565b6040516103459190611cc9565b60405180910390f35b34801561035a57600080fd5b5061037560048036038101906103709190611a5b565b610d6e565b6040516103829190611d3c565b60405180910390f35b34801561039757600080fd5b506103a0610db7565b6040516103ad9190611cc9565b60405180910390f35b3480156103c257600080fd5b506103cb610ddd565b6040516103d89190611cc9565b60405180910390f35b3480156103ed57600080fd5b506103f6610e01565b6040516104039190611d1a565b60405180910390f35b34801561041857600080fd5b50610433600480360381019061042e9190611b8a565b610e8f565b005b61044f600480360381019061044a9190611b0f565b611132565b005b34801561045d57600080fd5b5061047860048036038101906104739190611a84565b61127c565b6040516104859190611ce4565b60405180910390f35b34801561049a57600080fd5b506104b560048036038101906104b09190611c2b565b611314565b6040516104c29190611d3c565b60405180910390f35b60006380ac58cd7c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156105205760019050610671565b635b5e139f7c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156105735760019050610671565b63780e9d637c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156105c65760019050610671565b63449a52f87c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156106195760019050610671565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561066c5760019050610671565b600090505b919050565b600c805461068390611ee7565b80601f01602080910402602001604051908101604052809291908181526020018280546106af90611ee7565b80156106fc5780601f106106d1576101008083540402835291602001916106fc565b820191906000526020600020905b8154815290600101906020018083116106df57829003601f168201915b505050505081565b60006009600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b3373ffffffffffffffffffffffffffffffffffffffff166005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146107ac57600080fd5b816009600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000600280549050905090565b60606108788484848461137a565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450505050565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821061092657600080fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020828154811061099d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154905092915050565b60606109be8484848461137a565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450505050565b60003373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a7b57600080fd5b600060046000848152602001908152602001600020541480610aa257506000600280549050145b610aab57600080fd5b600080600280549050915083905060028190806001815401808255809150506001900390600052602060002001600090919091909150556003439080600181540180825580915050600190039060005260206000200160009091909190915055846005600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360076000600660008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080549050815260200190815260200160002081905550600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020849080600181540180825580915050600190039060005260206000200160009091909190915055600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190610c6d90611f4a565b91905055508473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f886604051610ccf9190611d3c565b60405180910390a360019250505092915050565b600060028281548110610d1f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b60006005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000600860008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600d8054610e0e90611ee7565b80601f0160208091040260200160405190810160405280929190818152602001828054610e3a90611ee7565b8015610e875780601f10610e5c57610100808354040283529160200191610e87565b820191906000526020600020905b815481529060010190602001808311610e6a57829003601f168201915b505050505081565b8015610fb057600073ffffffffffffffffffffffffffffffffffffffff16600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f2d57600080fd5b81600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506110c9565b600073ffffffffffffffffffffffffffffffffffffffff16600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561104957600080fd5b6000600a60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516111269190611ce4565b60405180910390a35050565b61113e8484848461137a565b818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4818373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f75c9e114f073c346aac7d1d7e9a3c3c14edabcdd27de07d1d9e425f45d318c5e600b60008781526020019081526020016000206001600b60008981526020019081526020016000208054905061121f9190611dc9565b81548110611256577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020015460405161126e9190611cff565b60405180910390a450505050565b60008173ffffffffffffffffffffffffffffffffffffffff16600a60008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614905092915050565b6000806004600084815260200190815260200160002054905060038181548110611367577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154915050919050565b60006005600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508473ffffffffffffffffffffffffffffffffffffffff166005600085815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461141d57600080fd5b3373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614611551573373ffffffffffffffffffffffffffffffffffffffff166009600085815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16148061154757503373ffffffffffffffffffffffffffffffffffffffff16600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b61155057600080fd5b5b60006009600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001600660008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490506116329190611dc9565b81548110611669577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206007600086815260200190815260200160002054815481106116fe577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200181905550600860008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919061175c90611ebd565b9190505550600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020839080600181540180825580915050600190039060005260206000200160009091909190915055600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919061181790611f4a565b9190505550836005600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060005b8251811015611997578281815181106118b3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916600b600086815260200190815260200160002060208361193f9190611f93565b81548110611976577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200181905550808061198f90611f4a565b915050611871565b505050505050565b60006119b26119ad84611d7c565b611d57565b9050828152602081018484840111156119ca57600080fd5b6119d5848285611e7b565b509392505050565b6000813590506119ec81612091565b92915050565b600081359050611a01816120a8565b92915050565b600081359050611a16816120bf565b92915050565b600082601f830112611a2d57600080fd5b8135611a3d84826020860161199f565b91505092915050565b600081359050611a55816120d6565b92915050565b600060208284031215611a6d57600080fd5b6000611a7b848285016119dd565b91505092915050565b60008060408385031215611a9757600080fd5b6000611aa5858286016119dd565b9250506020611ab6858286016119dd565b9150509250929050565b600080600060608486031215611ad557600080fd5b6000611ae3868287016119dd565b9350506020611af4868287016119dd565b9250506040611b0586828701611a46565b9150509250925092565b60008060008060808587031215611b2557600080fd5b6000611b33878288016119dd565b9450506020611b44878288016119dd565b9350506040611b5587828801611a46565b925050606085013567ffffffffffffffff811115611b7257600080fd5b611b7e87828801611a1c565b91505092959194509250565b60008060408385031215611b9d57600080fd5b6000611bab858286016119dd565b9250506020611bbc858286016119f2565b9150509250929050565b60008060408385031215611bd957600080fd5b6000611be7858286016119dd565b9250506020611bf885828601611a46565b9150509250929050565b600060208284031215611c1457600080fd5b6000611c2284828501611a07565b91505092915050565b600060208284031215611c3d57600080fd5b6000611c4b84828501611a46565b91505092915050565b611c5d81611dfd565b82525050565b611c6c81611e0f565b82525050565b611c7b81611e1b565b82525050565b6000611c8c82611dad565b611c968185611db8565b9350611ca6818560208601611e8a565b611caf81612080565b840191505092915050565b611cc381611e71565b82525050565b6000602082019050611cde6000830184611c54565b92915050565b6000602082019050611cf96000830184611c63565b92915050565b6000602082019050611d146000830184611c72565b92915050565b60006020820190508181036000830152611d348184611c81565b905092915050565b6000602082019050611d516000830184611cba565b92915050565b6000611d61611d72565b9050611d6d8282611f19565b919050565b6000604051905090565b600067ffffffffffffffff821115611d9757611d96612051565b5b611da082612080565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b6000611dd482611e71565b9150611ddf83611e71565b925082821015611df257611df1611fc4565b5b828203905092915050565b6000611e0882611e51565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015611ea8578082015181840152602081019050611e8d565b83811115611eb7576000848401525b50505050565b6000611ec882611e71565b91506000821415611edc57611edb611fc4565b5b600182039050919050565b60006002820490506001821680611eff57607f821691505b60208210811415611f1357611f12612022565b5b50919050565b611f2282612080565b810181811067ffffffffffffffff82111715611f4157611f40612051565b5b80604052505050565b6000611f5582611e71565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611f8857611f87611fc4565b5b600182019050919050565b6000611f9e82611e71565b9150611fa983611e71565b925082611fb957611fb8611ff3565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b61209a81611dfd565b81146120a557600080fd5b50565b6120b181611e0f565b81146120bc57600080fd5b50565b6120c881611e25565b81146120d357600080fd5b50565b6120df81611e71565b81146120ea57600080fd5b5056fea26469706673582212200bbe19f458108c1aff099be836757910e315386233d3d3043305de731d4736e464736f6c63430008030033
-\ No newline at end of file
diff --git a/python/eth_devbadge/data/BadgeToken.json b/python/eth_devbadge/data/BadgeToken.json
@@ -1 +0,0 @@
-[{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_operator","type":"address"},{"indexed":false,"internalType":"bool","name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_minter","type":"address"},{"indexed":true,"internalType":"address","name":"_beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"_data","type":"bytes32"}],"name":"TransferWithData","type":"event"},{"inputs":[{"internalType":"address","name":"_approved","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"declarator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_beneficiary","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"mintedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"bool","name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"payable","type":"function"}]
diff --git a/python/eth_devbadge/token.py b/python/eth_devbadge/token.py
@@ -1,244 +0,0 @@
-# standard imports
-import os
-
-# external imports
-from chainlib.eth.tx import (
- TxFormat,
- TxFactory,
- )
-from chainlib.eth.contract import (
- ABIContractEncoder,
- ABIContractType,
- abi_decode_single,
- )
-from chainlib.jsonrpc import jsonrpc_template
-from chainlib.eth.constant import ZERO_ADDRESS
-from hexathon import (
- add_0x,
- strip_0x,
- )
-from eth_erc20 import ERC20
-
-# local imports
-#from .interface import BadgeToken
-
-moddir = os.path.dirname(__file__)
-datadir = os.path.join(moddir, 'data')
-
-
-class BadgeToken(ERC20):
-
- __abi = None
- __bytecode = None
-
- @staticmethod
- def abi():
- if BadgeToken.__abi == None:
- f = open(os.path.join(datadir, 'BadgeToken.json'), 'r')
- BadgeToken.__abi = json.load(f)
- f.close()
- return BadgeToken.__abi
-
-
- @staticmethod
- def bytecode():
- if BadgeToken.__bytecode == None:
- f = open(os.path.join(datadir, 'BadgeToken.bin'))
- BadgeToken.__bytecode = f.read()
- f.close()
- return BadgeToken.__bytecode
-
-
- @staticmethod
- def gas(code=None):
- return 1200000
-
-
- def constructor(self, sender_address, declarator, name, symbol, tx_format=TxFormat.JSONRPC):
- code = BadgeToken.bytecode()
- enc = ABIContractEncoder()
- enc.address(declarator)
- enc.string(name)
- enc.string(symbol)
- code += enc.get()
- tx = self.template(sender_address, None, use_nonce=True)
- tx = self.set_code(tx, code)
- return self.finalize(tx, tx_format)
-
-
- def transfer(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC):
- raise NotImplementedError('EIP721 does not implement ERC20.transfer')
-
-
- def mint_to(self, contract_address, sender_address, address, token_id, tx_format=TxFormat.JSONRPC):
- enc = ABIContractEncoder()
- enc.method('mintTo')
- enc.typ(ABIContractType.ADDRESS)
- enc.typ(ABIContractType.UINT256)
- enc.address(address)
- enc.uint256(token_id)
- data = enc.get()
- tx = self.template(sender_address, contract_address, use_nonce=True)
- tx = self.set_code(tx, data)
- tx = self.finalize(tx, tx_format)
- return tx
-
-
- def set_approve_for_all(self, contract_address, sender_address, operator_address, flag, tx_format=TxFormat.JSONRPC):
- enc = ABIContractEncoder()
- enc.method('setApprovalForAll')
- enc.typ(ABIContractType.ADDRESS)
- enc.typ(ABIContractType.BOOLEAN)
- enc.address(operator_address)
- enc.uint256(int(flag))
- data = enc.get()
- tx = self.template(sender_address, contract_address, use_nonce=True)
- tx = self.set_code(tx, data)
- tx = self.finalize(tx, tx_format)
- return tx
-
-
- def set_operator(self, contract_address, sender_address, operator_address, tx_format=TxFormat.JSONRPC):
- return self.set_approve_for_all(contract_address, sender_address, operator_address, True, tx_format=tx_format)
-
-
- def remove_operator(self, contract_address, sender_address, operator_address, tx_format=TxFormat.JSONRPC):
- return self.set_approve_for_all(contract_address, sender_address, operator_address, False, tx_format=tx_format)
-
-
- def token_by_index(self, contract_address, idx, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('tokenByIndex')
- enc.typ(ABIContractType.UINT256)
- enc.uint256(idx)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('ownerOf')
- enc.typ(ABIContractType.UINT256)
- enc.uint256(token_id)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- def is_approved_for_all(self, contract_address, holder_address, operator_address, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('isApprovedForAll')
- enc.typ(ABIContractType.ADDRESS)
- enc.typ(ABIContractType.ADDRESS)
- enc.address(holder_address)
- enc.address(operator_address)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- def is_operator(self, contract_address, token_id, operator_address, sender_address=ZERO_ADDRESS):
- return self.is_approved_for_all(contract_address, token_id, operator_address, sender_address=sender_address)
-
-
- def get_approved(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('getApproved')
- enc.typ(ABIContractType.UINT256)
- enc.uint256(token_id)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- def minted_at(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('mintedAt')
- enc.typ(ABIContractType.UINT256)
- enc.uint256(token_id)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- def token_of_owner_by_index(self, contract_address, holder_address, idx, sender_address=ZERO_ADDRESS):
- o = jsonrpc_template()
- o['method'] = 'eth_call'
- enc = ABIContractEncoder()
- enc.method('tokenOfOwnerByIndex')
- enc.typ(ABIContractType.ADDRESS)
- enc.typ(ABIContractType.UINT256)
- enc.address(holder_address)
- enc.uint256(idx)
- data = add_0x(enc.get())
- tx = self.template(sender_address, contract_address)
- tx = self.set_code(tx, data)
- o['params'].append(self.normalize(tx))
- o['params'].append('latest')
- return o
-
-
- @classmethod
- def parse_owner_of(self, v):
- return abi_decode_single(ABIContractType.ADDRESS, v)
-
-
- @classmethod
- def parse_token_by_index(self, v):
- return abi_decode_single(ABIContractType.UINT256, v)
-
-
- @classmethod
- def parse_token_of_owner_by_index(self, v):
- return abi_decode_single(ABIContractType.UINT256, v)
-
-
- @classmethod
- def parse_total_supply(self, v):
- return abi_decode_single(ABIContractType.UINT256, v)
-
-
- @classmethod
- def parse_is_approved_for_all(self, v):
- return abi_decode_single(ABIContractType.BOOLEAN, v)
-
-
- @classmethod
- def parse_is_operator(self, v):
- return self.parse_is_approved_for_all(v)
-
-
- @classmethod
- def parse_get_approved(self, v):
- return abi_decode_single(ABIContractType.ADDRESS, v)
-
-
- @classmethod
- def parse_minted_at(self, v):
- return abi_decode_single(ABIContractType.UINT256, v)
diff --git a/python/eth_erc721/__init__.py b/python/eth_erc721/__init__.py
@@ -0,0 +1 @@
+from .erc721 import ERC721
diff --git a/python/eth_erc721/erc721.py b/python/eth_erc721/erc721.py
@@ -0,0 +1,164 @@
+# external imports
+from chainlib.eth.tx import (
+ TxFormat,
+ TxFactory,
+ )
+from chainlib.eth.contract import (
+ ABIContractEncoder,
+ ABIContractType,
+ abi_decode_single,
+ )
+from chainlib.jsonrpc import jsonrpc_template
+from chainlib.eth.constant import ZERO_ADDRESS
+from hexathon import (
+ add_0x,
+ )
+from eth_erc20 import ERC20
+from eth_owned import EIP173
+
+
+class ERC721(ERC20, EIP173):
+
+ def transfer(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC):
+ raise NotImplementedError('EIP721 does not implement ERC20.transfer')
+
+
+ def set_approve_for_all(self, contract_address, sender_address, operator_address, flag, tx_format=TxFormat.JSONRPC):
+ enc = ABIContractEncoder()
+ enc.method('setApprovalForAll')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.typ(ABIContractType.BOOLEAN)
+ enc.address(operator_address)
+ enc.uint256(int(flag))
+ data = enc.get()
+ tx = self.template(sender_address, contract_address, use_nonce=True)
+ tx = self.set_code(tx, data)
+ tx = self.finalize(tx, tx_format)
+ return tx
+
+
+ def set_operator(self, contract_address, sender_address, operator_address, tx_format=TxFormat.JSONRPC):
+ return self.set_approve_for_all(contract_address, sender_address, operator_address, True, tx_format=tx_format)
+
+
+ def remove_operator(self, contract_address, sender_address, operator_address, tx_format=TxFormat.JSONRPC):
+ return self.set_approve_for_all(contract_address, sender_address, operator_address, False, tx_format=tx_format)
+
+
+ def token_by_index(self, contract_address, idx, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('tokenByIndex')
+ enc.typ(ABIContractType.UINT256)
+ enc.uint256(idx)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+ def owner_of(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('ownerOf')
+ enc.typ(ABIContractType.UINT256)
+ enc.uint256(token_id)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+ def is_approved_for_all(self, contract_address, holder_address, operator_address, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('isApprovedForAll')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.typ(ABIContractType.ADDRESS)
+ enc.address(holder_address)
+ enc.address(operator_address)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+ def is_operator(self, contract_address, token_id, operator_address, sender_address=ZERO_ADDRESS):
+ return self.is_approved_for_all(contract_address, token_id, operator_address, sender_address=sender_address)
+
+
+ def get_approved(self, contract_address, token_id, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('getApproved')
+ enc.typ(ABIContractType.UINT256)
+ enc.uint256(token_id)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+
+ def token_of_owner_by_index(self, contract_address, holder_address, idx, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('tokenOfOwnerByIndex')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.typ(ABIContractType.UINT256)
+ enc.address(holder_address)
+ enc.uint256(idx)
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ o['params'].append('latest')
+ return o
+
+
+ @classmethod
+ def parse_owner_of(self, v):
+ return abi_decode_single(ABIContractType.ADDRESS, v)
+
+
+ @classmethod
+ def parse_token_by_index(self, v):
+ return abi_decode_single(ABIContractType.UINT256, v)
+
+
+ @classmethod
+ def parse_token_of_owner_by_index(self, v):
+ return abi_decode_single(ABIContractType.UINT256, v)
+
+
+ @classmethod
+ def parse_total_supply(self, v):
+ return abi_decode_single(ABIContractType.UINT256, v)
+
+
+ @classmethod
+ def parse_is_approved_for_all(self, v):
+ return abi_decode_single(ABIContractType.BOOLEAN, v)
+
+
+ @classmethod
+ def parse_is_operator(self, v):
+ return self.parse_is_approved_for_all(v)
+
+
+ @classmethod
+ def parse_get_approved(self, v):
+ return abi_decode_single(ABIContractType.ADDRESS, v)
diff --git a/python/requirements.txt b/python/requirements.txt
@@ -1 +1,2 @@
chainlib~=0.0.3a2
+eth_erc20~=0.0.9a2
diff --git a/python/tests/test_app.py b/python/tests/test_app.py
@@ -27,7 +27,7 @@ from hexathon import (
# local imports
-from eth_devbadge.token import BadgeToken
+from eth_badge.token import BadgeToken
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -78,7 +78,6 @@ class Test(EthTesterCase):
o = c.total_supply(self.address, sender_address=self.accounts[0])
r = self.rpc.do(o)
supply = c.parse_total_supply(r)
-
self.assertEqual(supply, 1)
o = c.minted_at(self.address, token_id, sender_address=self.accounts[0])
@@ -96,7 +95,6 @@ class Test(EthTesterCase):
o = c.owner_of(self.address, token_id, sender_address=self.accounts[0])
r = self.rpc.do(o)
owner_address = c.parse_owner_of(r)
-
self.assertEqual(self.accounts[1], owner_address)
o = c.token_of_owner_by_index(self.address, self.accounts[1], 0, sender_address=self.accounts[0])
@@ -215,7 +213,37 @@ class Test(EthTesterCase):
o = c.token_of_owner_by_index(self.address, self.accounts[2], 0, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(token_bytes.hex(), strip_0x(r))
-
+
+
+ def test_contract_ownership(self):
+ token_bytes = [
+ b'\xee' * 32,
+ b'\xdd' * 32,
+ b'\xcc' * 32,
+ ]
+ token_ids = []
+ for t in token_bytes:
+ token_id = int.from_bytes(t, byteorder='big')
+ token_ids.append(token_id)
+ c = self._mint(self.accounts[0], token_id)
+
+ o = c.total_supply(self.address, sender_address=self.accounts[0])
+ r = self.rpc.do(o)
+ supply = c.parse_total_supply(r)
+ self.assertEqual(supply, 3)
+
+ (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[4])
+ r = self.rpc.do(o)
+ o = receipt(tx_hash_hex)
+ r = self.conn.do(o)
+ self.assertEqual(r['status'], 1)
+
+ for t in token_ids:
+ o = c.owner_of(self.address, token_id, sender_address=self.accounts[0])
+ r = self.rpc.do(o)
+ owner_address = c.parse_owner_of(r)
+ self.assertEqual(self.accounts[4], owner_address)
+
if __name__ == '__main__':
unittest.main()
diff --git a/solidity/BadgeToken.sol b/solidity/BadgeToken.sol
@@ -2,8 +2,11 @@ pragma solidity ^0.8.0;
contract BadgeToken {
- address public declarator;
+ // EIP 173
address public owner;
+
+ // Points to Declarator implementer
+ address public declarator;
uint256[] token;
uint256[] tokenMintedAt;
@@ -32,6 +35,9 @@ contract BadgeToken {
// ERC-721
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
+ // EIP-173
+ event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
+
event TransferWithData(address indexed _from, address indexed _to, uint256 indexed _tokenId, bytes32 _data);
// Minter
@@ -44,6 +50,7 @@ contract BadgeToken {
symbol = _symbol;
}
+
// ERC-721
function balanceOf(address _owner) external view returns (uint256) {
return tokenOwnerCursor[_owner];
@@ -181,6 +188,28 @@ contract BadgeToken {
return tokenMintedAt[_tokenIndex];
}
+ // EIP-173
+ function transferOwnership(address _newOwner) external returns (bool) {
+ require(msg.sender == owner);
+
+ bytes memory zeroData;
+ address previousOwner;
+ uint256[] memory currentTokenOwnerIndex; // investigate; if source is storage, which of memory or storage does a copy
+
+ previousOwner = owner;
+ currentTokenOwnerIndex = tokenOwnerIndex[previousOwner];
+
+ for (uint256 i; i < currentTokenOwnerIndex.length; i++) {
+ transferCore(previousOwner, _newOwner, currentTokenOwnerIndex[i], zeroData);
+ }
+
+ owner = _newOwner;
+
+ emit OwnershipTransferred(previousOwner, _newOwner);
+ return true;
+ }
+
+
// EIP-165
function supportsInterface(bytes4 interfaceID) external pure returns (bool) {
if (interfaceID == 0x80ac58cd) { // EIP 721
diff --git a/solidity/Makefile b/solidity/Makefile
@@ -6,5 +6,5 @@ all:
$(SOLC) --abi BadgeToken.sol --evm-version byzantium | awk 'NR>3' > BadgeToken.json
install: all
- cp -v *{json,bin} ../python/eth_devbadge/data/
+ cp -v *{json,bin} ../python/eth_badge/data/