最终,合同是否能够在 B 的行为上签字(或代理签字)?
不。
A通过向合约发送必要的资金开始交易,然后合约根据规则分散资金。因此,A -> 合同,合同 -> B,可能还有合同 -> C。
虽然它不在提出的问题范围内,但如果 B 和/或 C 是不受信任的合同,它可能会帮助您避免以后进行重构以观察分离两个发送的最佳实践。您只需在存款步骤中进行会计处理,然后使用提款模式,因为 B & C 要求他们的权利(单独交易)。
希望能帮助到你。
更新:
这是一个粗略的大纲,可能会给你一些想法。我不确定 > 50 是历史总数还是单次付款 > 50。这是一个人为的示例,希望您为 B 和 C 传递两个有效地址,以便合约知道它们的地址。
您可以从任何地址 (A) 发送金额,并且合约将跟踪owedToB
和owedToC
。
您应该能够向withdraw()
B 或 C 发送交易以索取所欠余额。
为完整测试设置所有内容有点耗时,因此只需“按原样”呈现。
pragma solidity ^0.4.6;
contract Royalty {
address public B;
address public C;
uint public owedToB;
uint public owedToC;
event LogPaymentReceived(address sender, uint amount);
event LogPaid(address recipient, uint amount);
// pass in two addresses, B & C for this simple constructor
function Royalty(address addressB, address addressC) {
B = addressB;
C = addressC;
}
function pay()
public
payable
returns(bool success)
{
owedToB += msg.value;
// You can do B.balance > 50 but beware how it drops below 50 after withdrawal
// A little more involved, but you can have totalReceipts AND totalPayments so owedToB is totalReceipts - totalPayments
// It all depends on the business terms you're trying to enforce.
if(msg.value > 50) {
owedToC += 10;
owedToB -= 10;
}
LogPaymentReceived(msg.sender, msg.value);
return true;
}
function withdraw()
public
returns(uint amountSent)
{
if(msg.sender != B && msg.sender != C) throw; // only B & C can withdraw
uint amount;
if(msg.sender == B) {
amount = owedToB;
owedToB = 0;
if(!B.send(amount)) throw;
LogPaid(B,amount);
return amount;
}
if(msg.sender == C) {
amount = owedToC;
owedToC = 0;
if(!C.send(amount)) throw;
LogPaid(C,amount);
return amount;
}
// we shouldn't make it this far
throw;
}
}