Ich bin neu in der Solidity-Programmierung und schreibe intelligente Verträge für eine der Anwendungen. Hier sind meine beiden Verträge. Ich verwende truffle und testrpc als Werkzeug. Ich erhalte ständig Fehler. Anleitung brauchen. Ich habe frühere Threads mit ähnlichen Betreffzeilen gesehen, aber sie helfen nicht. Ich habe auch schon versucht, den Namen der Funktion zu ändern.
//Certificate.sol
contract Certificate {
address private addressSelf;
bytes32 private certName;
function Certificate(bytes32 _certName) {
addressSelf = msg.sender;
certName = _certName;
}
}
//Participant.sol
contract Participant {
address private addressSelf;
bytes32 private participantName;
struct CertStruct {
Certificate certificateData;
bool isCertificate;
}
mapping (address => CertStruct) public certStructs;
mapping (uint => address) public certIndex;
uint public noOfCerts;
function Participant(bytes32 _partName) {
addressSelf = msg.sender; // just set the self
participantName = _partName;
noOfCerts = 0;
}
function isCertGranted(address certAddress) public constant returns(bool) {
return certStructs[certAddress].isCertificate;
}
function grantCertToParticipant(address certAddress, Certificate certificate) payable public returns (bool)
{
if(!isCertGranted(certAddress)) return false;
CertStruct memory newCertStruct;
newCertStruct.certificateData = certificate;
newCertStruct.isCertificate = true;
certStructs[certAddress] = newCertStruct;
certIndex[noOfCerts] = certAddress;
noOfCerts++;
return true;
}
}
//participant.js
var CertificateSol = artifacts.require("./Certificate.sol");
var ParticipantSol = artifacts.require("./Participant.sol");
contract('Participant', function() {
it("should put certificate in the one participant", function() {
var newCert;
var newPart;
return CertificateSol.new('CertName').then(function(newCertInstance) {
newCert = newCertInstance;
}
return ParticipantSol.new('Name of Participant').then(function(newPartInstance) {
newPart = newPartInstance;
newPart.grantCertToParticipant.sendTransaction(newCert.address, newCert, { from : web3.eth.accounts[0], gas: 3000000 }).then(function(returnFlag){
newPart.noOfCerts.call().then(function(certNumber){
console.log('certNumber is ' + certNumber.toString(10));
});
}).catch(function(err){
console.log('I am at grantCertToParticipant err ' + err);
});
});
}
Erstens müssen Sie die Transaktion nicht explizit senden, es reicht aus, eine Methode aufzurufen:
newPart.grantCertToParticipant(newCert.address, newCert, { from : web3.eth.accounts[0], gas: 3000000 })
Zweitens newCert
ist es ein Vertrags-Proxy-Objekt, also übergeben Sie es nicht an den web3-Aufruf. Es reicht aus, nur newCert.address zu senden. Ich werde nur die Adresse in der Methodensignatur hinterlassen:
function grantCertToParticipant(address certAddress) payable public returns (bool)
Diese Zeile ergibt leider keinen Sinn:
newCertStruct.certificateData = certificate;
Da Sie keinen Vertrag speichern können, the whole
sondern nur eine Referenz in Form einer Adresse, ist dies überflüssig.
golra03
Jakob Wojciechowski
constant
. 2) Adresse und Schnittstelle reichen aus, um auf den Vertrag in der Kette zuzugreifen. 3) Übergeben Sie den Vertragsproxy nicht,newCert
es wird weiterhin ein Fehler ausgegeben.golra03