2017-05-06 16 views
2

在復仇智能合同IBM Example,有這樣下面的代碼:是{來自:thesponsor,值:10000000,gas:3000000}一個msg對象在堅實?

personal.unlockAccount(thesponsor,"password"); 
ss.pledge("Good luck with the run!", {from: thesponsor, value: 10000000, gas: 3000000}); 

然而,承諾的功能是不是應付改性劑和只接受一個參數作爲參數:

function pledge(bytes32 _message) { 
    if (msg.value == 0 || complete || refunded) throw; 
    pledges[numPledges] = Pledge(msg.value, msg.sender, _message); 
    numPledges++; 
} 

那麼,堅定性會自動將{from:thesponsor,value:10000000,gas:3000000}視爲一個msg對象,從我的賬戶轉移ethers?

我剛剛發現這個功能有點兒werid。如果我寫了一個恰好包含關鍵字「from」和「value」的json對象,我會不小心轉移任何資金嗎?

回答

1

我希望你已經找到了解決你的問題了半年下來,但如果你沒有的話..

是的,你是在你的觀察是,{from: thesponsor, value: 10000000, gas: 3000000}被解釋爲transactionObject正確。這是因爲在以太坊上導致狀態改變(意味着你創建,更新或刪除數據)的任何transaction需要transactionObject(如上面所示的那個)允許你的代碼在區塊鏈上執行。

在下面的代碼片段中,你可以看到pledge功能使上線4的狀態變化和5.這僅僅需要您爲交易提供gas。此外,pledge利用msg.value,這是您在承諾中發送的以太坊數額值,由value表示。

1 // add a new pledge 
2 function pledge(bytes32 _message) { 
3 if (msg.value == 0 || complete || refunded) throw; 
4 pledges[numPledges] = Pledge(msg.value, msg.sender, _message); 
5 numPledges++; 
6 } 

關於你提到的第二個問題,請https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction看到transactionObject的結構。以太坊中的功能(如果它們進行狀態更改)將先接受功能的參數,然後是transactionObject。因此,只要確保您不會意外地編寫transactionObject,因爲它會被解釋爲交易。