@@ -90,9 +90,11 @@ public boolean validate() throws ContractValidateException {
9090 }
9191 Preconditions .checkNotNull (transferAssetContract .getAssetName (), "AssetName is null" );
9292 Preconditions .checkNotNull (transferAssetContract .getAmount (), "Amount is null" );
93+
9394 if (transferAssetContract .getOwnerAddress ().equals (transferAssetContract .getToAddress ())) {
9495 throw new ContractValidateException ("Cannot transfer asset to yourself." );
9596 }
97+
9698 byte [] ownerKey = transferAssetContract .getOwnerAddress ().toByteArray ();
9799 if (!this .dbManager .getAccountStore ().has (ownerKey )) {
98100 throw new ContractValidateException ();
@@ -113,14 +115,18 @@ public boolean validate() throws ContractValidateException {
113115 long amount = transferAssetContract .getAmount ();
114116
115117 AccountCapsule ownerAccount = this .dbManager .getAccountStore ().get (ownerKey );
118+ if (ownerAccount == null ) {
119+ throw new ContractValidateException ();
120+ }
116121 Map <String , Long > asset = ownerAccount .getAssetMap ();
117122
118123 if (asset .isEmpty ()) {
119124 throw new ContractValidateException ();
120125 }
121126
122- Long assetAmount = asset .get (ByteArray .toStr (nameKey ));
123- if (amount <= 0 || null == assetAmount || amount > assetAmount || assetAmount <= 0 ) {
127+ Long assetBalance = asset .get (ByteArray .toStr (nameKey ));
128+
129+ if (amount <= 0 || null == assetBalance || amount > assetBalance || assetBalance <= 0 ) {
124130 throw new ContractValidateException ();
125131 }
126132 } catch (InvalidProtocolBufferException e ) {
0 commit comments