I have a simple contract as below:-
contract MultiAsset {
address public creator;
mapping(string => address) assetOwner;
event NewAsset(string indexed assetName, address indexed to);
event AssetTransferred(string indexed assetName, address indexed from, address indexed to);
function MultiAsset() {
creator = msg.sender;
}
function assignOwner(string assetName, address to) {
if (msg.sender == creator) {
//new asset entry
if (assetOwner[assetName] != 0x0) {
throw;
} else {
assetOwner[assetName] = to;
NewAsset(assetName, to);
}
} else {
throw;
}
}
function getAssetOwner(string assetName) constant returns (address owner){
owner = assetOwner[assetName];
return owner;
}
function transfer(string assetName, address to) {
//transfer can be done only by the owner
if (msg.sender == assetOwner[assetName]) {
assetOwner[assetName] = to;
AssetTransferred(assetName, msg.sender, to);
} else {
throw;
}
}}
The contract is to save a key value pair of assets like as below:-
"Asset1" - Addr1 "Asset2" - Addr2
Now my assignOwner function is working fine but when I call transfer function it doesn't work. I get an invalid jump in the debug.traceTransaction of the transfer tx.
Is there something wrong with the transfer function code?
Also if I am watching for events, nothing is getting printed?
var event = assetContract.NewAsset({}, '', function (error, result) {
if (!error) {
console.log("Asset Creation: " + result.args.assetName + " to To address:" + result.args.to);
} else {
console.log('error:' + error);
}
});
throw
is implemented as invalid jump, and it reverts pretty much everything, including events. So this condition must be returning falsemsg.sender == assetOwner[assetName]
for some reason.