def set_transporter(self,public_key,data,timestamp=000): """Creates a new transoporter in state""" address = addresser.get_transporter_address(public_key) otper = otp_pb2.Otp() address_otp = addresser.get_otp_address(data.mobilenumber,data.otp) state_entries_otp = self._context.get_state( addresses=[address_otp], timeout=self._timeout) otper.ParseFromString(state_entries_otp[0].data) if not state_entries_otp: raise InvalidTransaction('No otp was verified on this number') elif otper.otp != data.otp : raise InvalidTransaction('Wrong otp retry dude') transporter = transoporter_pb2.Transporter( public_key=public_key, full_name=data.full_name, timestamp=data.timestamp ,aadhar_card=data.aadhar_card,State=data.State,pincode=data.pincode,mobilenumber=data.mobilenumber ,district = data.district , driving_license = data.driving_license ) state_entries = self._context.get_state( addresses=[address], timeout=self._timeout) if state_entries: raise InvalidTransaction('Already exist , you have an account') data = transoporter.SerializeToString() updated_state = {} updated_state[address] = data self._context.set_state(updated_state, timeout=self._timeout)
def set_otp(self,public_key,data,timestamp=000): """Creates an otp state for otp verification # TODO: verify that it came from otp server """ address = addresser.get_otp_address(data.mobilenumber,data.otp) #this is called good practice otpPayload = otp_pb2.Otp( otp = data.otp, mobilenumber= data.mobilenumber , timestamp = data.timestamp ) state_enties = self._context.get_state( addresses = [address], timeout=self._timeout) payloada = otpPayload.SerializeToString() updated_state = {} updated_state[address] = payloada self._context.set_state(updated_state,timeout=self._timeout)
context = create_context('secp256k1') private_key = context.new_random_private_key() signer = CryptoFactory(context).new_signer(private_key) public_key = signer.get_public_key().as_hex() payload = agpayload_pb2.Realpayload() payload.Action = agpayload_pb2.action.Value('register_farmer') payload.reg_far.aadhar_card = 'dfv98fsdff98s83' payload.reg_far.timestamp = 12242343 payload.reg_far.full_name = 'Bro Code' payload.reg_far.otp = 1234 payload.reg_far.State = enums_pb2.state.Value('Gujarat') payload.reg_far.pincode = 123456 payload.reg_far.mobilenumber = 9999999999 payload.reg_far.district = 'sachin' input = [addresser.get_farmer_address(public_key),addresser.get_otp_address(9999999999,1234)] print(input) payload_bytes = payload.SerializeToString() txn_header_bytes = TransactionHeader( family_name='agriculture_market', family_version='0.1', inputs=input, outputs=input, signer_public_key=signer.get_public_key().as_hex(), # In this example, we're signing the batch with the same private key, # but the batch can be signed by another party, in which case, the # public key will need to be associated with that key. batcher_public_key=signer.get_public_key().as_hex(), # In this example, there are no dependencies. This list should include # an previous transaction header signatures that must be applied for
from sawtooth_signing import create_context from sawtooth_signing import CryptoFactory import urllib.request from urllib.error import HTTPError import addresser context = create_context('secp256k1') private_key = context.new_random_private_key() signer = CryptoFactory(context).new_signer(private_key) public_key = signer.get_public_key().as_hex() payload = agpayload_pb2.Realpayload() payload.Action = agpayload_pb2.action.Value('otp_transaction') payload.otp_tra.timestamp = 1224 payload.otp_tra.mobilenumber = 9999999999 payload.otp_tra.otp = 1234 input = addresser.get_otp_address(9999999999, 1234) print(input) payload_bytes = payload.SerializeToString() txn_header_bytes = TransactionHeader( family_name='agriculture_market', family_version='0.1', inputs=[input], outputs=[input], signer_public_key=signer.get_public_key().as_hex(), # In this example, we're signing the batch with the same private key, # but the batch can be signed by another party, in which case, the # public key will need to be associated with that key. batcher_public_key=signer.get_public_key().as_hex(), # In this example, there are no dependencies. This list should include # an previous transaction header signatures that must be applied for # this transaction to successfully commit.