交易会在我的智能合约中的什么地方发生

Where would a transaction take place in my Smart Contract

我正在制作一个简单的智能合约,它本质上是一个人们可以用字符串(UI 来签署)然后传递给下一个人(使用他们的以太网地址)的分类帐。我只是想创造一些可以在人与人之间传递的东西,同时记录它的旅程。

'transferring'签名账本的逻辑全部在智能合约中完成,它作为映射存在,地址的键值从0 到 1 表示所有权(一次拥有它的人)。因为没有 ether/actual 货币价值的实际转移,实际的以太坊交易会在这个合约中发生在哪里?

另外,为了签署分类帐,我验证了签署它的 public 密钥在映射中具有 1 作为其值,但是我如何检查该人是否拥有该 public 密钥(使用私钥)?

到目前为止我的 solidity 代码:

pragma solidity ^0.4.4;

contract Pass{
mapping(address => bool) ownership;
mapping(address => string) notes;

constructor(address genesis) public {
    ownership[genesis] = true; //this address starts with it
}

function checkOwnership(address p) public view returns(bool){
    if(ownership[p]){
        return true;
    }
    return false;
}

function sign(string signedNote) public returns(uint){ // 1 on success 0 on fail
    if(checkOwnership(msg.sender)){ //if msg.sender owns the note
        notes[msg.sender] = signedNote;
        return 1;
    }
    return 0;
}

function pass(address recipient) public returns(uint){ // 1 on success 0 on fail
    if(checkOwnership(msg.sender)){ //if msg.sender owns the note
        ownership[msg.sender] = 0;
        ownership[recipient] = 1;
        return 1;
    }
    return 0;
}

function viewNotes(address participant) public returns(string){ // signed note on success nothing on fail
    if(notes[participant] !== 0){
        return (notes(participant));   
    }
}

}

The logic of 'transferring' the signing-ledger is all done within the smart contract, with it existing as a mapping and the key value of an address changing from 0 to 1 signifying ownership (1 person owning it at a time)

这是一种常见的模式,称为所有者模式。您可以通过简单地跟踪单个所有者地址并更新它来简化此操作,而不是使用映射,因为您只关心当前所有者。简单如:

address public owner;

modifier onlyOwner() {
    require(msg.sender == owner);
    _;
}

constructor() {
    owner = msg.sender;
}

function transferOwnership(address _owner) onlyOwner {
    owner = _owner;
}

Open Zeppelin 拥有更完整的所有权实现 here

Because there's no actual transfer of ether/actual monetary value, where would actual ethereum transactions be occurring in this contract?

交易不需要以太币移动。您可以使用 0 值交易调用合约上的任何 public/external 函数,并将数据传递给它。交易将像其他任何交易一样在区块链上执行,并且 运行 您在合约中调用的代码。

Also to sign the ledger I verify that the public key signing it has 1 as its value in the mapping, but how would I check that that person owns that public key (using a private key)?

您已经在检查 msg.sender 是否与列入白名单的地址匹配。对于基本交易,这意味着交易已由 msg.sender 中的地址签署(msg.sender 也可以是合约,如果另一个合约调用你的。要检查在所有情况下谁实际签署了交易,你必须使用 tx.origin).