contract KYCCHECK{
function KYCCHECK(){}
struct User{
uint id;
bool isVerified;
string fname;
string mname;
string lname;
string genderValue;
string maritalStat;
string stat;
string identity;
}
mapping(uint => User) kyclist;
function setKYCData(uint uid,string firstname,string middlename,string lastname,string gvalue,string maritalVal,string statusVal,string identityVal) {
kyclist[uid].fname = firstname;
kyclist[uid].mname = middlename;
kyclist[uid].lname = lastname;
kyclist[uid].genderValue = gvalue;
kyclist[uid].maritalStat = maritalVal;
kyclist[uid].stat = statusVal;
kyclist[uid].identity = identityVal;
}
function getFirstName(uint uid) constant returns (string retFNameVal) {
retFNameVal = kyclist[uid].fname;
return retFNameVal;
}
function getMiddleName(uint uid) constant returns (string retMNameVal) {
retMNameVal = kyclist[uid].mname;
return retMNameVal;
}
function getLastName(uint uid) constant returns (string retLNameVal) {
retLNameVal = kyclist[uid].lname;
return retLNameVal;
}
function getGender(uint uid) constant returns(string retGenderVal) {
retGenderVal = kyclist[uid].genderValue;
return retGenderVal;
}
function getMaritalStatus(uint uid) constant returns(string retMaritalVal){
retMaritalVal= kyclist[uid].maritalStat;
return retMaritalVal;
}
function getStatus(uint uid) constant returns(string retStatus){
retStatus = kyclist[uid].stat;
return retStatus;
}
function getIdentity(uint uid)constant returns(string retIdentity){
retIdentity = kyclist[uid].identity;
return retIdentity;
}
}
Hello everyone,
This the contract i am trying to implement.
I have a form(using bootstrap with form defined "") and i need to set and get the data through form.
Problem is when i pass more than 3 arguments in setKYCData function (in above contracts)and execute get function, the value isn't displayed.
but when set is modified to take 3 arguments and get function is called with 3 arguments it works fine.
please ask if you need any more details, if anybody can share a code to create a form using solidity, web3 that'll be appreciable.
thanks in adv
Related
I am new to Solidity and building a Todo List project.
I still got below error messages in the deductTask function even after using keccak256(abi.encodePacked())
to pack my string variables
error 1 . Type bytes32 is not implicitly convertible to expected type string memory.
error 2 . Operator == not compatible with types string memory and string memory
pragma solidity >=0.4.22 <0.9.0;
contract myTodoList {
// Model a Task
struct Task {
uint id;
string content;
bool completed;
}
// Read/write Tasks
mapping(uint => Task) public Tasks;
// Store Tasks Count
uint public TasksCount = 0;
function addTask (string memory _content) public {
TasksCount ++;
Tasks[TasksCount] = Task(TasksCount, _content, false);
}
Task TaskTemp;
function deductTask (string memory _contentClicked) public {
string memory comparedContent;
uint i ;
for(i = 1; i <= TasksCount; i++) {
TaskTemp = Tasks[i];
comparedContent = TaskTemp.content;
comparedContent = keccak256(abi.encodePacked(comparedContent));
//comparedContent = keccak256(abi.encodePacked(comparedContent));
_contentClicked = keccak256(abi.encodePacked(_contentClicked));
//_contentClicked = keccak256(abi.encodePacked(_contentClicked));
if(_contentClicked == comparedContent ){
delete Tasks[i];
}
}
TasksCount --;
}
constructor () public {
addTask("my first task");
addTask("my second task");
}
}
So I have been trying to compare two objects by their fields.
I have noticed there is no equals method in dart. But there are the identical function and the == operator.
I can't seem to understand why there is no equals method. What if I want to do this?
class Name {
String fname;
String lname;
String get firstName => this.fname;
void set firstName(String fname) => this.fname = fname;
String get lastName => this.lname;
void set lastName(String lname) => this.lname = lname;
Name({this.fname, this.lname});
#override
String toString() {
return this.firstName + " " + this.lastName;
}
bool equals(Name n2) {
return this.firstName == n2.firstName && this.lastName == n2.lastName
? true
: false;
}
}
void main(List<String> args) {
Name n1 = new Name();
n1.firstName = "James";
n1.lastName = "Bond";
Name n2 = new Name();
n2.firstName = "James";
n2.lastName = "Bond";
print(n1.equals(n2)); // true
print(identical(n1, n2)); // false
print(n1 == n2); // false
}
What can I do instead of making my own equals. Or does dart expect you to do this manually.
identical will not return true even if the first name and last name of the two objects you are comparing are the same. That's because they are not the same instances. Each instance has its own identity and own hashcode.
You could override the == operator and the hashcode. Then you will be able to compare two different instances. The Equatable-Package already does that for you so you can use the == operator two compare two different instances: https://pub.dev/packages/equatable
You can write code just like this
#override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
return false;
/// do smth
}
#override
int get hashCode {
}
Why it doesn't work with Auth::id(), but works with a hardcoded value like 1.
The following doesn't work:
public function getTwitterUser()
{
$auth_id = Auth::id();
$getuser = Twitterac::where('user_id', $auth_id)->get();
return $getuser;
}
But this does:
public function getTwitterUser()
{
$auth_id = 1;
$getuser = Twitterac::where('user_id', $auth_id)->get();
return $getuser;
}
I found SelfDestruct problem in geth
I didn't call SelfDestruct on my smart contract
but, after restart my server PC which implements geth, my contract suddenly selfdestruct.
I have no sense about this kind of problem.
is there any condition of selfdestruct which I didn't know?
pragma solidity^0.4.19;
contract Dan_v1_1 {
struct DanInfo {
string file_path;
string kor_name;
string personal_key;
string eng_name;
uint8 gradeOfpoomDan;
string danCertificate;
uint[] regDateHistory;
bool flag;
}
mapping (string => DanInfo) danInfo;
mapping (uint => string) indexOfDanInfo;
uint private danInfoCount = 0;
address contractOwner;
function Dan_v1_1() public{
contractOwner = msg.sender;
}
function setInitDanInfo (string file_path,string kor_name, string personal_key,string eng_name,
uint8 gradeOfpoomDan,string danCertificate, uint []regDateHistory, bool flag)
public{
require (keccak256(danInfo[personal_key].personal_key) != keccak256(personal_key));
danInfo[personal_key] = DanInfo(file_path,kor_name, personal_key,eng_name,gradeOfpoomDan,danCertificate,regDateHistory,flag);
indexOfDanInfo[danInfoCount++] = personal_key;
}
function getDanInfoCount () public constant returns(uint) {
return danInfoCount;
}
function getDanInfo (string personal_key) public constant returns(string,string, string, string, uint8, string, uint[], bool) {
DanInfo memory temp = danInfo[personal_key];
return(temp.file_path,temp.kor_name, temp.personal_key, temp.eng_name, temp.gradeOfpoomDan, temp.danCertificate, temp.regDateHistory, temp.flag);
}
function killContract() public{
if(contractOwner == msg.sender) {
selfdestruct(contractOwner);
}
}
}
I want to create a contract between a Patient and Doctor where the first Patient fills his details like name, age, and problems he is facing. As soon as the above details are filled function createDoctor() is called and name, age and problems are sent as parameters to the Doctor. Considering the details filled by the patient the doctor sets the Physician and updates the problems faced by the patient if any. But I am not able to figure out the way to implement the above statement. Below is the code where I am asking the details of Patient and send it to the Doctor. Now I am not able to implement the Doctor part. Below is the code:
Patient.sol
pragma solidity ^0.4.6;
import './Doctor.sol';
contract Patient {
bytes private name = "";
bytes private dateOfBirth="NA";
bytes private problemFaced = "";
address public myDoctor;
// Event that is fired when patient is changed
event patientChanged(string whatChanged);
function createDoctor() public {
myDoctor = new Doctor(getName(), getDateOfBirth(), getGender(), problemFaced);
}
function ProblemFaced(string problems) public {
problemFaced = bytes(problems);
}
function getName() internal view returns (bytes) {
return name; // First_Name Last_Name
}
function getDateOfBirth() internal view returns (bytes) {
return dateOfBirth; // YYYYMMDD
}
function setName(string _name) public {
name = bytes(_name); // First_Name Last_Name
emit patientChanged("name changed"); // fire the event
}
function setDateOfBirth(string _dateOfBirth) public {
dateOfBirth = bytes(_dateOfBirth); // YYYYMMDD
emit patientChanged("dateOfBirth changed"); // fire the event
}
}
Doctor.sol
pragma solidity ^0.4.6;
contract Doctor {
// the address of the owner (the patient)
address public owner;
uint balance;
// address of physician that can add allergies
string public physician;
// name of the patient LAST^FIRST
string public patient_name;
string public patient_dob;
string public patient_gender;
string public patient_problem = '';
modifier isOwnerPatient {
require(msg.sender == owner);
_;
}
function Doctor(bytes _name, bytes _dob, bytes _gender, bytes _problems) {
owner = msg.sender;
patient_name = string(_name);
patient_dob = string(_dob);
patient_gender = string(_gender);
patient_problem = string(_problems);
}
function updateProblem(bytes _condition) {
patient_problem = strConcat(patient_problem, string(_condition));
}
// allows owner to set the physician that can add allergies
function SetPhysician(string _physician) isOwnerPatient {
physician = _physician;
}
function strConcat(string _a, string _b) internal pure returns (string){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory abcde = new string(_ba.length + 2 + _bb.length);
delete abcde;
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
babcde[k++] = ",";
babcde[k++] = " ";
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
return string(babcde);
}
}
Is there any possibility of using owner and msg.sender while executing above problem statement.