Ejemplo n.º 1
0
    def set_farmer(self, public_key, data, timestamp=000):
        """Creates a new farmer in state"""

        address = addresser.get_farmer_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')

        farmer = farmer_pb2.Farmer(
            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)

        state_entries = self._context.get_state(
            addresses=[address], timeout=self._timeout)

        if state_entries:
            raise InvalidTransaction('Already exist , you have an account')

        data = farmer.SerializeToString()
        updated_state = {}
        updated_state[address] = data
        self._context.set_state(updated_state, timeout=self._timeout)
Ejemplo n.º 2
0
 def get_farmer(self,public_key):
     """Fetches data of the farmer
         only for testing mode dev build may not include this"""
     address = addresser.get_farmer_address(public_key)
     farmer = farmer_pb2.Farmer()
     state_entries = self._context.get_state(
         addresses=[address], timeout=self._timeout)
     if state_entries:
         return farmer.ParseFromString(state_entries[0].data)
Ejemplo n.º 3
0
    def create_asset(self,public_key,data,timestamp=000):
        """It creates asset can't you read dumbo !"""
        address = addresser.get_asset_address(data.public_key)
        address_farmer = addresser.get_farmer_address(data.current_owner_pubkey)
        data_type = self.type(data)
        farmer =  farmer_pb2.Farmer()
        assetPayload = enums_pb2.assets(
            weight = data.weight,current_owner_pubkey = data.current_owner_pubkey,
            current_owner_pincode = data.current_owner_pincode,type_of_food = data.type_of_food,
            timestamp = timestamp , Status = enums_pb2.status.Value('OrderAdded')
            ,public_key = data.public_key)

        if (data_type[1] == 1):
            assetPayload.Pulses = data_type[0]
        elif (data_type[1] == 2):
            assetPayload.Vegetable_short = data_type[0]
        elif (data_type[1] == 3):
            assetPayload.Vegetable_long = data_type[0]
        elif (data_type[1] == 4):
            assetPayload.Fruits_long = data_type[0]
        elif (data_type[1] == 5):
            assetPayload.Fruits_short = data_type[0]
        elif (data_type[1] == 6):
            assetPayload.Grains = data_type[0]
        else:
            raise InvalidTransaction('Wrong type_of_food')

        state_entries = self._context.get_state(
            addresses=[address], timeout=self._timeout)
        state_entries_farm = self._context.get_state(
            addresses=[address_farmer] ,timeout=self._timeout)
        if state_entries:
            raise InvalidTransaction('Already exist , asset already used')
        if not state_entries_farm:
            raise InvalidTransaction('No farmer by this pubkey exist')
        farmer.ParseFromString(state_entries_farm[0].data)
        add_asset = farmer.assets_sold.add()
        add_asset = assetPayload
        data_farm = farmer.SerializeToString()
        data = assetsPayload.SerializeToString()
        updated_state_farm = {}
        updatad_state_farm[address_farmer] = data_farm
        updated_state = {}
        updated_state[address] = data
        self._context.set_state(updated_state, timeout=self._timeout)
        self._context.set_state(updated_state_farm, timeout=self._timeout)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
print(
    f"public key of famer {public_key} and public key of asset {public_key_asset}"
)
payload = agpayload_pb2.Realpayload()
payload.Action = agpayload_pb2.action.create_asset
payload.cre_ass.public_key = public_key_asset
payload.cre_ass.weight = 5
payload.cre_ass.current_owner_pubkey = public_key
payload.cre_ass.current_owner_pincode = 394230
payload.cre_ass.type_of_food = enums_pb2.type.vegetable_shortt
payload.cre_ass.vegetable_short = enums_pb2.vegetable_shortt.Tomato
payload.cre_ass.timestamp = 00000
payload.cre_ass.district = 'sachin'
payload.cre_ass.Status = enums_pb2.status.OrderAdded
input = [
    addresser.get_farmer_address(public_key),
    addresser.get_asset_address(public_key_asset)
]

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