|
| 1 | +/* |
| 2 | + * java-tron is free software: you can redistribute it and/or modify |
| 3 | + * it under the terms of the GNU General Public License as published by |
| 4 | + * the Free Software Foundation, either version 3 of the License, or |
| 5 | + * (at your option) any later version. |
| 6 | + * |
| 7 | + * java-tron is distributed in the hope that it will be useful, |
| 8 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + * GNU General Public License for more details. |
| 11 | + * |
| 12 | + * You should have received a copy of the GNU General Public License |
| 13 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | + */ |
| 15 | + |
| 16 | +package org.tron.core.actuator; |
| 17 | + |
| 18 | +import com.google.common.base.Preconditions; |
| 19 | +import com.google.protobuf.Any; |
| 20 | +import com.google.protobuf.ByteString; |
| 21 | +import com.google.protobuf.InvalidProtocolBufferException; |
| 22 | +import org.slf4j.Logger; |
| 23 | +import org.slf4j.LoggerFactory; |
| 24 | +import org.tron.core.capsule.AssetIssueCapsule; |
| 25 | +import org.tron.core.db.Manager; |
| 26 | +import org.tron.core.exception.ContractExeException; |
| 27 | +import org.tron.core.exception.ContractValidateException; |
| 28 | +import org.tron.protos.Contract.AssetIssueContract; |
| 29 | + |
| 30 | +public class AssetIssueActuator extends AbstractActuator { |
| 31 | + |
| 32 | + private static final Logger logger = LoggerFactory.getLogger("AssetIssueActuator"); |
| 33 | + |
| 34 | + AssetIssueActuator(Any contract, Manager dbManager) { |
| 35 | + super(contract, dbManager); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean execute() throws ContractExeException { |
| 40 | + try { |
| 41 | + AssetIssueContract assetIssueContract = contract.unpack(AssetIssueContract.class); |
| 42 | + |
| 43 | + AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract); |
| 44 | + |
| 45 | + dbManager.getAssetIssueStore() |
| 46 | + .put(assetIssueCapsule.getName().toByteArray(), assetIssueCapsule); |
| 47 | + } catch (InvalidProtocolBufferException e) { |
| 48 | + throw new ContractExeException(); |
| 49 | + } |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public boolean validate() throws ContractValidateException { |
| 55 | + if (!this.contract.is(AssetIssueContract.class)) { |
| 56 | + throw new ContractValidateException(); |
| 57 | + } |
| 58 | + |
| 59 | + try { |
| 60 | + final AssetIssueContract assetIssueContract = this.contract.unpack(AssetIssueContract.class); |
| 61 | + |
| 62 | + Preconditions.checkNotNull(assetIssueContract.getOwnerAddress(), "OwnerAddress is null"); |
| 63 | + Preconditions.checkNotNull(assetIssueContract.getName(), "name is null"); |
| 64 | + |
| 65 | + if (this.dbManager.getAssetIssueStore().get(assetIssueContract.getName().toByteArray()) |
| 66 | + != null) { |
| 67 | + throw new ContractValidateException(); |
| 68 | + } |
| 69 | + |
| 70 | + } catch (InvalidProtocolBufferException e) { |
| 71 | + throw new ContractValidateException(); |
| 72 | + } |
| 73 | + |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public ByteString getOwnerAddress() { |
| 79 | + return null; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public long calcFee() { |
| 84 | + return 0; |
| 85 | + } |
| 86 | +} |
0 commit comments