event-msg

Simple, embedded news post vehicle for EVM smart contracts
Log | Files | Refs

commit ef3ded9835d5bd1f04ec79da3de815d6730dfd2d
parent aadd6d2346f4b9f1f976db7ffb71466b13af2ae9
Author: lash <dev@holbrook.no>
Date:   Fri, 17 Feb 2023 23:13:52 +0000

Add prefix generator

Diffstat:
Mpython/eth_event_msg/__init__.py | 25+++++++++++++++++++++++++
Mpython/eth_event_msg/data/Msg.bin | 4++--
Mpython/eth_event_msg/data/Msg.json | 2+-
Mpython/tests/test_basic.py | 11++++++++++-
Msolidity/Msg.sol | 34++++++++++++++++++++++++++++------
5 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/python/eth_event_msg/__init__.py b/python/eth_event_msg/__init__.py @@ -74,6 +74,23 @@ class EventMsg(TxFactory): o = j.finalize(o) return o + + def to_uri(self, contract_address, v, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('toUri') + enc.typ(ABIContractType.BYTES) + enc.bytes(v) + 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') + o = j.finalize(o) + return o + @classmethod def parse_token_spec(self, v): @@ -82,3 +99,11 @@ class EventMsg(TxFactory): logg.debug('llll {} {}'.format(l, v[64:128])) r = v[128:128+(l*2)] return r + + + @classmethod + def parse_to_uri(self, v): + v = strip_0x(v) + l = int(v[64:128], 16) + r = v[128:128+(l*2)] + return r diff --git a/python/eth_event_msg/data/Msg.bin b/python/eth_event_msg/data/Msg.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b5062000065602060126040518060400160405280600681526020017f736861323536000000000000000000000000000000000000000000000000000081525062000086640100000000026401000000009004565b6200008060126200035c640100000000026401000000009004565b620007db565b6060819050601081511115620000d3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000ca90620005b3565b60405180910390fd5b620000dd620004ec565b6000600790505b60008160ff16106200014157600060088262000101919062000611565b60ff1660ff9060020a029050600086821667ffffffffffffffff1611156200012a575062000141565b8180620001379062000657565b92505050620000e4565b60018162000150919062000685565b826020019060ff16908160ff16815250506008816007620001729190620006c1565b6200017e919062000611565b60ff168567ffffffffffffffff169060020a02780100000000000000000000000000000000000000000000000002826080019077ffffffffffffffffffffffffffffffffffffffffffffffff1916908177ffffffffffffffffffffffffffffffffffffffffffffffff1916815250508251826040019060ff16908160ff1681525050826200020c906200076b565b82606001906fffffffffffffffffffffffffffffffff191690816fffffffffffffffffffffffffffffffff19168152505085826000019060ff16908160ff1681525050816000808767ffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff16021790555060408201518160000160026101000a81548160ff021916908360ff16021790555060608201518160000160036101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060808201518160000160136101000a81548167ffffffffffffffff0219169083780100000000000000000000000000000000000000000000000090040217905550905050505050505050565b6000806000838152602001908152602001600020905060008160000160009054906101000a900460ff1660ff16116200039457600080fd5b8060016000820160009054906101000a900460ff168160000160006101000a81548160ff021916908360ff1602179055506000820160019054906101000a900460ff168160000160016101000a81548160ff021916908360ff1602179055506000820160029054906101000a900460ff168160000160026101000a81548160ff021916908360ff1602179055506000820160039054906101000a9004700100000000000000000000000000000000028160000160036101000a8154816fffffffffffffffffffffffffffffffff0219169083700100000000000000000000000000000000900402179055506000820160139054906101000a90047801000000000000000000000000000000000000000000000000028160000160136101000a81548167ffffffffffffffff02191690837801000000000000000000000000000000000000000000000000900402179055509050505050565b6040518060a00160405280600060ff168152602001600060ff168152602001600060ff16815260200160006fffffffffffffffffffffffffffffffff19168152602001600077ffffffffffffffffffffffffffffffffffffffffffffffff191681525090565b600082825260208201905092915050565b7f4552525f5052454649585f544f4f5f4c4f4e4700000000000000000000000000600082015250565b60006200059b60138362000552565b9150620005a88262000563565b602082019050919050565b60006020820190508181036000830152620005ce816200058c565b9050919050565b600060ff82169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006200061e82620005d5565b91506200062b83620005d5565b92508282026200063b81620005d5565b915080821462000650576200064f620005e2565b5b5092915050565b60006200066482620005d5565b9150600082036200067a5762000679620005e2565b5b600182039050919050565b60006200069282620005d5565b91506200069f83620005d5565b9250828201905060ff811115620006bb57620006ba620005e2565b5b92915050565b6000620006ce82620005d5565b9150620006db83620005d5565b9250828203905060ff811115620006f757620006f6620005e2565b5b92915050565b600081519050919050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffff0000000000000000000000000000000082169050919050565b600062000752825162000718565b80915050919050565b60008160020a8302905092915050565b60006200077882620006fd565b82620007848462000708565b9050620007918162000744565b92506010821015620007d457620007cf7fffffffffffffffffffffffffffffffff00000000000000000000000000000000836010036008026200075b565b831692505b5050919050565b61145780620007eb6000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c0100000000000000000000000000000000000000000000000000000000900480639a7c5e9f116100785780639a7c5e9f14610146578063ad0dec2f14610162578063b238d60314610192578063ccc094c2146101c6576100a5565b806318cbbcfc146100aa5780632c1758c1146100c857806331a5995d146100f857806386fe212d14610116575b600080fd5b6100b26101e2565b6040516100bf9190610b37565b60405180910390f35b6100e260048036038101906100dd9190610b92565b6101e7565b6040516100ef9190610bda565b60405180910390f35b61010061021a565b60405161010d9190610b37565b60405180910390f35b610130600480360381019061012b9190610b92565b610220565b60405161013d9190610b37565b60405180910390f35b610160600480360381019061015b9190610b92565b610307565b005b61017c60048036038101906101779190610d3b565b610496565b6040516101899190610e03565b60405180910390f35b6101ac60048036038101906101a79190610b92565b610758565b6040516101bd959493929190610eb7565b60405180910390f35b6101e060048036038101906101db9190611017565b6107f7565b005b600381565b6000600382106101f657600080fd5b6000820361020b576003600254149050610215565b8160025483161490505b919050565b60025481565b600060108210610265576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161025c906110e3565b60405180910390fd5b60006002548316146102ac576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102a39061114f565b60405180910390fd5b8160026000828254179250508190555060036002541415157f6b7e2e653f93b645d4ed7292d6429f96637084363e477c8aaea1a43ed13c284e6002546040516102f59190610b37565b60405180910390a26002549050919050565b6000806000838152602001908152602001600020905060008160000160009054906101000a900460ff1660ff161161033e57600080fd5b8060016000820160009054906101000a900460ff168160000160006101000a81548160ff021916908360ff1602179055506000820160019054906101000a900460ff168160000160016101000a81548160ff021916908360ff1602179055506000820160029054906101000a900460ff168160000160026101000a81548160ff021916908360ff1602179055506000820160039054906101000a9004700100000000000000000000000000000000028160000160036101000a8154816fffffffffffffffffffffffffffffffff0219169083700100000000000000000000000000000000900402179055506000820160139054906101000a90047801000000000000000000000000000000000000000000000000028160000160136101000a81548167ffffffffffffffff02191690837801000000000000000000000000000000000000000000000000900402179055509050505050565b60606000600160000160019054906101000a900460ff1660ff16600160000160009054906101000a900460ff1660ff1684516104d2919061119e565b6104dc919061119e565b67ffffffffffffffff8111156104f5576104f4610c10565b5b6040519080825280601f01601f1916602001820160405280156105275781602001600182028036833780820191505090505b50905060005b600160000160019054906101000a900460ff1660ff168110156105ff57600160000160139054906101000a90047801000000000000000000000000000000000000000000000000028160088110610587576105866111d2565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028282815181106105bd576105bc6111d2565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806105f790611201565b91505061052d565b600160000160009054906101000a900460ff167f010000000000000000000000000000000000000000000000000000000000000002828281518110610647576106466111d2565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061068190611201565b91505060005b845181101561074d578481815181106106a3576106a26111d2565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382846106fa919061119e565b8151811061070b5761070a6111d2565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061074590611201565b915050610687565b508192505050919050565b60006020528060005260406000206000915090508060000160009054906101000a900460ff16908060000160019054906101000a900460ff16908060000160029054906101000a900460ff16908060000160039054906101000a900470010000000000000000000000000000000002908060000160139054906101000a9004780100000000000000000000000000000000000000000000000002905085565b6060819050601081511115610841576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161083890611295565b60405180910390fd5b610849610ab8565b6000600790505b60008160ff16106108a557600060088261086a91906112b5565b60ff1660ff9060020a029050600086821667ffffffffffffffff16111561089157506108a5565b818061089c906112f2565b92505050610850565b6001816108b2919061131b565b826020019060ff16908160ff168152505060088160076108d29190611350565b6108dc91906112b5565b60ff168567ffffffffffffffff169060020a02780100000000000000000000000000000000000000000000000002826080019077ffffffffffffffffffffffffffffffffffffffffffffffff1916908177ffffffffffffffffffffffffffffffffffffffffffffffff1916815250508251826040019060ff16908160ff168152505082610968906113ba565b82606001906fffffffffffffffffffffffffffffffff191690816fffffffffffffffffffffffffffffffff19168152505085826000019060ff16908160ff1681525050816000808767ffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff16021790555060408201518160000160026101000a81548160ff021916908360ff16021790555060608201518160000160036101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060808201518160000160136101000a81548167ffffffffffffffff0219169083780100000000000000000000000000000000000000000000000090040217905550905050505050505050565b6040518060a00160405280600060ff168152602001600060ff168152602001600060ff16815260200160006fffffffffffffffffffffffffffffffff19168152602001600077ffffffffffffffffffffffffffffffffffffffffffffffff191681525090565b6000819050919050565b610b3181610b1e565b82525050565b6000602082019050610b4c6000830184610b28565b92915050565b6000604051905090565b600080fd5b600080fd5b610b6f81610b1e565b8114610b7a57600080fd5b50565b600081359050610b8c81610b66565b92915050565b600060208284031215610ba857610ba7610b5c565b5b6000610bb684828501610b7d565b91505092915050565b60008115159050919050565b610bd481610bbf565b82525050565b6000602082019050610bef6000830184610bcb565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610c4882610bff565b810181811067ffffffffffffffff82111715610c6757610c66610c10565b5b80604052505050565b6000610c7a610b52565b9050610c868282610c3f565b919050565b600067ffffffffffffffff821115610ca657610ca5610c10565b5b610caf82610bff565b9050602081019050919050565b82818337600083830152505050565b6000610cde610cd984610c8b565b610c70565b905082815260208101848484011115610cfa57610cf9610bfa565b5b610d05848285610cbc565b509392505050565b600082601f830112610d2257610d21610bf5565b5b8135610d32848260208601610ccb565b91505092915050565b600060208284031215610d5157610d50610b5c565b5b600082013567ffffffffffffffff811115610d6f57610d6e610b61565b5b610d7b84828501610d0d565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610dbe578082015181840152602081019050610da3565b60008484015250505050565b6000610dd582610d84565b610ddf8185610d8f565b9350610def818560208601610da0565b610df881610bff565b840191505092915050565b60006020820190508181036000830152610e1d8184610dca565b905092915050565b600060ff82169050919050565b610e3b81610e25565b82525050565b60007fffffffffffffffffffffffffffffffff0000000000000000000000000000000082169050919050565b610e7681610e41565b82525050565b60007fffffffffffffffff00000000000000000000000000000000000000000000000082169050919050565b610eb181610e7c565b82525050565b600060a082019050610ecc6000830188610e32565b610ed96020830187610e32565b610ee66040830186610e32565b610ef36060830185610e6d565b610f006080830184610ea8565b9695505050505050565b610f1381610e25565b8114610f1e57600080fd5b50565b600081359050610f3081610f0a565b92915050565b600067ffffffffffffffff82169050919050565b610f5381610f36565b8114610f5e57600080fd5b50565b600081359050610f7081610f4a565b92915050565b600067ffffffffffffffff821115610f9157610f90610c10565b5b610f9a82610bff565b9050602081019050919050565b6000610fba610fb584610f76565b610c70565b905082815260208101848484011115610fd657610fd5610bfa565b5b610fe1848285610cbc565b509392505050565b600082601f830112610ffe57610ffd610bf5565b5b813561100e848260208601610fa7565b91505092915050565b6000806000606084860312156110305761102f610b5c565b5b600061103e86828701610f21565b935050602061104f86828701610f61565b925050604084013567ffffffffffffffff8111156110705761106f610b61565b5b61107c86828701610fe9565b9150509250925092565b600082825260208201905092915050565b7f4552525f494e56414c49445f5354415445000000000000000000000000000000600082015250565b60006110cd601183611086565b91506110d882611097565b602082019050919050565b600060208201905081810360008301526110fc816110c0565b9050919050565b7f4552525f414c52454144595f4c4f434b45440000000000000000000000000000600082015250565b6000611139601283611086565b915061114482611103565b602082019050919050565b600060208201905081810360008301526111688161112c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006111a982610b1e565b91506111b483610b1e565b92508282019050808211156111cc576111cb61116f565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600061120c82610b1e565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361123e5761123d61116f565b5b600182019050919050565b7f4552525f5052454649585f544f4f5f4c4f4e4700000000000000000000000000600082015250565b600061127f601383611086565b915061128a82611249565b602082019050919050565b600060208201905081810360008301526112ae81611272565b9050919050565b60006112c082610e25565b91506112cb83610e25565b92508282026112d981610e25565b91508082146112eb576112ea61116f565b5b5092915050565b60006112fd82610e25565b9150600082036113105761130f61116f565b5b600182039050919050565b600061132682610e25565b915061133183610e25565b9250828201905060ff81111561134a5761134961116f565b5b92915050565b600061135b82610e25565b915061136683610e25565b9250828203905060ff81111561137f5761137e61116f565b5b92915050565b6000819050602082019050919050565b60006113a18251610e41565b80915050919050565b60008160020a8302905092915050565b60006113c582610d84565b826113cf84611385565b90506113da81611395565b9250601082101561141a576114157fffffffffffffffffffffffffffffffff00000000000000000000000000000000836010036008026113aa565b831692505b505091905056fea26469706673582212209f52446ae313333c552aa40888a89c4e202d49749cdbdfed323b694c995852a164736f6c63430008110033 -\ No newline at end of file +60806040523480156200001157600080fd5b5062000065602060126040518060400160405280600681526020017f736861323536000000000000000000000000000000000000000000000000000081525062000086640100000000026401000000009004565b620000806012620003aa640100000000026401000000009004565b6200080e565b6000600160ff166002541614620000d4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000cb9062000502565b60405180910390fd5b606081905060108151111562000121576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620001189062000574565b60405180910390fd5b6200012b6200043b565b6000600790505b60008160ff16106200018f5760006008826200014f9190620005d2565b60ff1660ff9060020a029050600086821667ffffffffffffffff1611156200017857506200018f565b8180620001859062000618565b9250505062000132565b6001816200019e919062000646565b826020019060ff16908160ff16815250506008816007620001c0919062000682565b620001cc9190620005d2565b60ff168567ffffffffffffffff169060020a02780100000000000000000000000000000000000000000000000002826080019077ffffffffffffffffffffffffffffffffffffffffffffffff1916908177ffffffffffffffffffffffffffffffffffffffffffffffff1916815250508251826040019060ff16908160ff1681525050826200025a906200072c565b82606001906fffffffffffffffffffffffffffffffff191690816fffffffffffffffffffffffffffffffff19168152505085826000019060ff16908160ff1681525050816000808767ffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff16021790555060408201518160000160026101000a81548160ff021916908360ff16021790555060608201518160000160036101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060808201518160000160136101000a81548167ffffffffffffffff0219169083780100000000000000000000000000000000000000000000000090040217905550905050505050505050565b6000600160ff166002541614620003f8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620003ef90620007ec565b60405180910390fd5b6000806000838152602001908152602001600020905060008160000160009054906101000a900460ff1660ff16116200043057600080fd5b816001819055505050565b6040518060a00160405280600060ff168152602001600060ff168152602001600060ff16815260200160006fffffffffffffffffffffffffffffffff19168152602001600077ffffffffffffffffffffffffffffffffffffffffffffffff191681525090565b600082825260208201905092915050565b7f4552525f5345414c5f434f4445434c4953540000000000000000000000000000600082015250565b6000620004ea601283620004a1565b9150620004f782620004b2565b602082019050919050565b600060208201905081810360008301526200051d81620004db565b9050919050565b7f4552525f5052454649585f544f4f5f4c4f4e4700000000000000000000000000600082015250565b60006200055c601383620004a1565b9150620005698262000524565b602082019050919050565b600060208201905081810360008301526200058f816200054d565b9050919050565b600060ff82169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000620005df8262000596565b9150620005ec8362000596565b9250828202620005fc8162000596565b9150808214620006115762000610620005a3565b5b5092915050565b6000620006258262000596565b9150600082036200063b576200063a620005a3565b5b600182039050919050565b6000620006538262000596565b9150620006608362000596565b9250828201905060ff8111156200067c576200067b620005a3565b5b92915050565b60006200068f8262000596565b91506200069c8362000596565b9250828203905060ff811115620006b857620006b7620005a3565b5b92915050565b600081519050919050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffff0000000000000000000000000000000082169050919050565b6000620007138251620006d9565b80915050919050565b60008160020a8302905092915050565b60006200073982620006be565b826200074584620006c9565b9050620007528162000705565b925060108210156200079557620007907fffffffffffffffffffffffffffffffff00000000000000000000000000000000836010036008026200071c565b831692505b5050919050565b7f4552525f5345414c5f434f444543000000000000000000000000000000000000600082015250565b6000620007d4600e83620004a1565b9150620007e1826200079c565b602082019050919050565b600060208201905081810360008301526200080781620007c5565b9050919050565b611727806200081e6000396000f3fe608060405234801561001057600080fd5b50600436106100b0576000357c01000000000000000000000000000000000000000000000000000000009004806386fe212d1161008357806386fe212d146101515780639a7c5e9f14610181578063ad0dec2f1461019d578063b238d603146101cd578063ccc094c214610201576100b0565b806318cbbcfc146100b55780632c1758c1146100d357806331a5995d14610103578063779ab66714610121575b600080fd5b6100bd61021d565b6040516100ca9190610c95565b60405180910390f35b6100ed60048036038101906100e89190610cf0565b610222565b6040516100fa9190610d38565b60405180910390f35b61010b610255565b6040516101189190610c95565b60405180910390f35b61013b60048036038101906101369190610e99565b61025b565b6040516101489190610f61565b60405180910390f35b61016b60048036038101906101669190610cf0565b610421565b6040516101789190610c95565b60405180910390f35b61019b60048036038101906101969190610cf0565b610508565b005b6101b760048036038101906101b29190610e99565b610595565b6040516101c49190610fd8565b60405180910390f35b6101e760048036038101906101e29190610cf0565b61086b565b6040516101f895949392919061108c565b60405180910390f35b61021b600480360381019061021691906111ec565b61090a565b005b600381565b60006003821061023157600080fd5b60008203610246576003600254149050610250565b8160025483161490505b919050565b60025481565b6060600060606000806000600154815260200190815260200160002092508260000160029054906101000a900460ff1660ff16905060018161029d919061128a565b67ffffffffffffffff8111156102b6576102b5610d6e565b5b6040519080825280601f01601f1916602001820160405280156102e85781602001600182028036833780820191505090505b50915060005b818110156103a2578360000160039054906101000a900470010000000000000000000000000000000002816010811061032a576103296112be565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028382815181106103605761035f6112be565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061039a906112ed565b9150506102ee565b50603a7f01000000000000000000000000000000000000000000000000000000000000000282600184516103d69190611335565b815181106103e7576103e66112be565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350819350505050919050565b600060108210610466576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045d906113b5565b60405180910390fd5b60006002548316146104ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a490611421565b60405180910390fd5b8160026000828254179250508190555060036002541415157f6b7e2e653f93b645d4ed7292d6429f96637084363e477c8aaea1a43ed13c284e6002546040516104f69190610c95565b60405180910390a26002549050919050565b6000600160ff166002541614610553576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161054a9061148d565b60405180910390fd5b6000806000838152602001908152602001600020905060008160000160009054906101000a900460ff1660ff161161058a57600080fd5b816001819055505050565b606060006060600080600154815260200190815260200160002091508160000160019054906101000a900460ff1660ff168260000160009054906101000a900460ff1660ff1685516105e7919061128a565b6105f1919061128a565b67ffffffffffffffff81111561060a57610609610d6e565b5b6040519080825280601f01601f19166020018201604052801561063c5781602001600182028036833780820191505090505b50905060005b8260000160019054906101000a900460ff1660ff16811015610712578260000160139054906101000a9004780100000000000000000000000000000000000000000000000002816008811061069a576106996112be565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028282815181106106d0576106cf6112be565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061070a906112ed565b915050610642565b8260000160009054906101000a900460ff167f010000000000000000000000000000000000000000000000000000000000000002828281518110610759576107586112be565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610793906112ed565b91505060005b855181101561085f578581815181106107b5576107b46112be565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000283828461080c919061128a565b8151811061081d5761081c6112be565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610857906112ed565b915050610799565b50819350505050919050565b60006020528060005260406000206000915090508060000160009054906101000a900460ff16908060000160019054906101000a900460ff16908060000160029054906101000a900460ff16908060000160039054906101000a900470010000000000000000000000000000000002908060000160139054906101000a9004780100000000000000000000000000000000000000000000000002905085565b6000600160ff166002541614610955576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094c906114f9565b60405180910390fd5b606081905060108151111561099f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161099690611565565b60405180910390fd5b6109a7610c16565b6000600790505b60008160ff1610610a035760006008826109c89190611585565b60ff1660ff9060020a029050600086821667ffffffffffffffff1611156109ef5750610a03565b81806109fa906115c2565b925050506109ae565b600181610a1091906115eb565b826020019060ff16908160ff16815250506008816007610a309190611620565b610a3a9190611585565b60ff168567ffffffffffffffff169060020a02780100000000000000000000000000000000000000000000000002826080019077ffffffffffffffffffffffffffffffffffffffffffffffff1916908177ffffffffffffffffffffffffffffffffffffffffffffffff1916815250508251826040019060ff16908160ff168152505082610ac69061168a565b82606001906fffffffffffffffffffffffffffffffff191690816fffffffffffffffffffffffffffffffff19168152505085826000019060ff16908160ff1681525050816000808767ffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360ff16021790555060408201518160000160026101000a81548160ff021916908360ff16021790555060608201518160000160036101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060808201518160000160136101000a81548167ffffffffffffffff0219169083780100000000000000000000000000000000000000000000000090040217905550905050505050505050565b6040518060a00160405280600060ff168152602001600060ff168152602001600060ff16815260200160006fffffffffffffffffffffffffffffffff19168152602001600077ffffffffffffffffffffffffffffffffffffffffffffffff191681525090565b6000819050919050565b610c8f81610c7c565b82525050565b6000602082019050610caa6000830184610c86565b92915050565b6000604051905090565b600080fd5b600080fd5b610ccd81610c7c565b8114610cd857600080fd5b50565b600081359050610cea81610cc4565b92915050565b600060208284031215610d0657610d05610cba565b5b6000610d1484828501610cdb565b91505092915050565b60008115159050919050565b610d3281610d1d565b82525050565b6000602082019050610d4d6000830184610d29565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610da682610d5d565b810181811067ffffffffffffffff82111715610dc557610dc4610d6e565b5b80604052505050565b6000610dd8610cb0565b9050610de48282610d9d565b919050565b600067ffffffffffffffff821115610e0457610e03610d6e565b5b610e0d82610d5d565b9050602081019050919050565b82818337600083830152505050565b6000610e3c610e3784610de9565b610dce565b905082815260208101848484011115610e5857610e57610d58565b5b610e63848285610e1a565b509392505050565b600082601f830112610e8057610e7f610d53565b5b8135610e90848260208601610e29565b91505092915050565b600060208284031215610eaf57610eae610cba565b5b600082013567ffffffffffffffff811115610ecd57610ecc610cbf565b5b610ed984828501610e6b565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610f1c578082015181840152602081019050610f01565b60008484015250505050565b6000610f3382610ee2565b610f3d8185610eed565b9350610f4d818560208601610efe565b610f5681610d5d565b840191505092915050565b60006020820190508181036000830152610f7b8184610f28565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000610faa82610f83565b610fb48185610f8e565b9350610fc4818560208601610efe565b610fcd81610d5d565b840191505092915050565b60006020820190508181036000830152610ff28184610f9f565b905092915050565b600060ff82169050919050565b61101081610ffa565b82525050565b60007fffffffffffffffffffffffffffffffff0000000000000000000000000000000082169050919050565b61104b81611016565b82525050565b60007fffffffffffffffff00000000000000000000000000000000000000000000000082169050919050565b61108681611051565b82525050565b600060a0820190506110a16000830188611007565b6110ae6020830187611007565b6110bb6040830186611007565b6110c86060830185611042565b6110d5608083018461107d565b9695505050505050565b6110e881610ffa565b81146110f357600080fd5b50565b600081359050611105816110df565b92915050565b600067ffffffffffffffff82169050919050565b6111288161110b565b811461113357600080fd5b50565b6000813590506111458161111f565b92915050565b600067ffffffffffffffff82111561116657611165610d6e565b5b61116f82610d5d565b9050602081019050919050565b600061118f61118a8461114b565b610dce565b9050828152602081018484840111156111ab576111aa610d58565b5b6111b6848285610e1a565b509392505050565b600082601f8301126111d3576111d2610d53565b5b81356111e384826020860161117c565b91505092915050565b60008060006060848603121561120557611204610cba565b5b6000611213868287016110f6565b935050602061122486828701611136565b925050604084013567ffffffffffffffff81111561124557611244610cbf565b5b611251868287016111be565b9150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061129582610c7c565b91506112a083610c7c565b92508282019050808211156112b8576112b761125b565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006112f882610c7c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361132a5761132961125b565b5b600182019050919050565b600061134082610c7c565b915061134b83610c7c565b92508282039050818111156113635761136261125b565b5b92915050565b7f4552525f494e56414c49445f5354415445000000000000000000000000000000600082015250565b600061139f601183610eed565b91506113aa82611369565b602082019050919050565b600060208201905081810360008301526113ce81611392565b9050919050565b7f4552525f414c52454144595f4c4f434b45440000000000000000000000000000600082015250565b600061140b601283610eed565b9150611416826113d5565b602082019050919050565b6000602082019050818103600083015261143a816113fe565b9050919050565b7f4552525f5345414c5f434f444543000000000000000000000000000000000000600082015250565b6000611477600e83610eed565b915061148282611441565b602082019050919050565b600060208201905081810360008301526114a68161146a565b9050919050565b7f4552525f5345414c5f434f4445434c4953540000000000000000000000000000600082015250565b60006114e3601283610eed565b91506114ee826114ad565b602082019050919050565b60006020820190508181036000830152611512816114d6565b9050919050565b7f4552525f5052454649585f544f4f5f4c4f4e4700000000000000000000000000600082015250565b600061154f601383610eed565b915061155a82611519565b602082019050919050565b6000602082019050818103600083015261157e81611542565b9050919050565b600061159082610ffa565b915061159b83610ffa565b92508282026115a981610ffa565b91508082146115bb576115ba61125b565b5b5092915050565b60006115cd82610ffa565b9150600082036115e0576115df61125b565b5b600182039050919050565b60006115f682610ffa565b915061160183610ffa565b9250828201905060ff81111561161a5761161961125b565b5b92915050565b600061162b82610ffa565b915061163683610ffa565b9250828203905060ff81111561164f5761164e61125b565b5b92915050565b6000819050602082019050919050565b60006116718251611016565b80915050919050565b60008160020a8302905092915050565b600061169582610f83565b8261169f84611655565b90506116aa81611665565b925060108210156116ea576116e57fffffffffffffffffffffffffffffffff000000000000000000000000000000008360100360080261167a565b831692505b505091905056fea2646970667358221220c68d69e7d53370b3d4ba76b2af0ab8ac1c3772de400a3f1869f3577fc644aa4d64736f6c63430008110033 +\ No newline at end of file diff --git a/python/eth_event_msg/data/Msg.json b/python/eth_event_msg/data/Msg.json @@ -1 +1 @@ -[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[{"internalType":"uint8","name":"_length","type":"uint8"},{"internalType":"uint64","name":"_codecId","type":"uint64"},{"internalType":"string","name":"_uriPrefix","type":"string"}],"name":"addCodec","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"multiCodecs","outputs":[{"internalType":"uint8","name":"l","type":"uint8"},{"internalType":"uint8","name":"codecRLength","type":"uint8"},{"internalType":"uint8","name":"prefixRLength","type":"uint8"},{"internalType":"bytes16","name":"prefix","type":"bytes16"},{"internalType":"bytes8","name":"codec","type":"bytes8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"seal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_codec","type":"uint256"}],"name":"setMsgCodec","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_digest","type":"bytes"}],"name":"toHash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"}] +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_final","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_sealState","type":"uint256"}],"name":"SealStateChange","type":"event"},{"inputs":[{"internalType":"uint8","name":"_length","type":"uint8"},{"internalType":"uint64","name":"_codecId","type":"uint64"},{"internalType":"string","name":"_uriPrefix","type":"string"}],"name":"addCodec","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"isSealed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"multiCodecs","outputs":[{"internalType":"uint8","name":"l","type":"uint8"},{"internalType":"uint8","name":"codecRLength","type":"uint8"},{"internalType":"uint8","name":"prefixRLength","type":"uint8"},{"internalType":"bytes16","name":"prefix","type":"bytes16"},{"internalType":"bytes8","name":"codec","type":"bytes8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_state","type":"uint256"}],"name":"seal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sealState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_codec","type":"uint256"}],"name":"setMsgCodec","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_digest","type":"bytes"}],"name":"toHash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_digest","type":"bytes"}],"name":"toUri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}] diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py @@ -37,7 +37,7 @@ class Test(EthTesterCase): self.address = to_checksum_address(rr['contract_address']) - def test_set_codec(self): + def test_hash(self): nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) c = EventMsg(self.chain_spec) #, signer=self.signer, nonce_oracle=nonce_oracle) o = c.to_hash(self.address, hash_of_foo, sender_address=self.accounts[0]) @@ -47,6 +47,15 @@ class Test(EthTesterCase): self.assertEqual(mh[4:68], hash_of_foo) + def test_uri(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) + c = EventMsg(self.chain_spec) #, signer=self.signer, nonce_oracle=nonce_oracle) + o = c.to_uri(self.address, hash_of_foo, sender_address=self.accounts[0]) + r = self.conn.do(o) + mh = c.parse_token_spec(r) + print(bytes.fromhex(mh).decode('utf-8')) + + if __name__ == '__main__': unittest.main() diff --git a/solidity/Msg.sol b/solidity/Msg.sol @@ -11,7 +11,7 @@ contract Msg { } mapping (uint256 => MultiHash) public multiCodecs; - MultiHash msgCodec; + uint256 msgCodec; // Implements Sealer uint256 public sealState; @@ -26,6 +26,7 @@ contract Msg { } function addCodec(uint8 _length, uint64 _codecId, string memory _uriPrefix) public { + require(sealState & CODECLIST_STATE == 0, 'ERR_SEAL_CODECLIST'); bytes memory prefixBytes; prefixBytes = bytes(_uriPrefix); @@ -51,12 +52,13 @@ contract Msg { } function setMsgCodec(uint256 _codec) public { + require(sealState & CODECLIST_STATE == 0, 'ERR_SEAL_CODEC'); MultiHash storage _hsh; _hsh = multiCodecs[_codec]; require(_hsh.l > 0); - msgCodec = _hsh; + msgCodec = _codec; } // Implements Sealer @@ -78,14 +80,17 @@ contract Msg { } function toHash(bytes memory _digest) public view returns(bytes memory) { - bytes memory r = new bytes(_digest.length + msgCodec.l + msgCodec.codecRLength); + MultiHash storage m; + bytes memory r; + m = multiCodecs[msgCodec]; + r = new bytes(_digest.length + m.l + m.codecRLength); uint256 i = 0; - for (i; i < msgCodec.codecRLength; i++) { - r[i] = msgCodec.codec[i]; + for (i; i < m.codecRLength; i++) { + r[i] = m.codec[i]; } - r[i] = bytes1(msgCodec.l); + r[i] = bytes1(m.l); i++; for (uint256 j = 0; j < _digest.length; j++) { r[i+j] = _digest[j]; @@ -94,4 +99,21 @@ contract Msg { return r; } + function toUri(bytes memory _digest) public view returns(string memory) { + MultiHash storage m; + + bytes memory codecString; + uint256 l; + + m = multiCodecs[msgCodec]; + l = m.prefixRLength; + codecString = new bytes(l+1); + for (uint256 i; i < l; i++) { + codecString[i] = m.prefix[i]; + } + codecString[codecString.length - 1] = 0x3a; + return string(codecString); + + } + }