1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17- use std:: iter :: FromIterator ;
17+ use std:: convert :: TryFrom ;
1818
1919use cjson:: uint:: Uint ;
2020use ckey:: { NetworkId , PlatformAddress , Public , Signature } ;
2121use ctypes:: transaction:: { Action as ActionType , AssetMintOutput as AssetMintOutputType } ;
2222use ctypes:: ShardId ;
2323use primitives:: { Bytes , H160 , H256 } ;
24- use rustc_serialize:: hex:: { FromHex , FromHexError , ToHex } ;
24+ use rustc_serialize:: hex:: { FromHex , ToHex } ;
2525
2626use super :: super :: errors:: ConversionError ;
2727use super :: { AssetMintOutput , AssetTransferInput , AssetTransferOutput , OrderOnTransfer } ;
@@ -489,9 +489,9 @@ impl ActionWithTracker {
489489 }
490490}
491491
492- // FIXME: Use TryFrom.
493- impl From < Action > for Result < ActionType , ConversionError > {
494- fn from ( from : Action ) -> Self {
492+ impl TryFrom < Action > for ActionType {
493+ type Error = ConversionError ;
494+ fn try_from ( from : Action ) -> Result < Self , Self :: Error > {
495495 Ok ( match from {
496496 Action :: MintAsset {
497497 network_id,
@@ -511,7 +511,7 @@ impl From<Action> for Result<ActionType, ConversionError> {
511511 Some ( registrar) => Some ( registrar. try_into_address ( ) ?) ,
512512 None => None ,
513513 } ;
514- let output_content = Result :: < AssetMintOutputType , FromHexError > :: from ( * output) ?;
514+ let output_content = AssetMintOutputType :: try_from ( * output) ?;
515515 ActionType :: MintAsset {
516516 network_id,
517517 shard_id,
@@ -534,13 +534,13 @@ impl From<Action> for Result<ActionType, ConversionError> {
534534 approvals,
535535 expiration,
536536 } => {
537- let iter_outputs = outputs. into_iter ( ) . map ( From :: from ) ;
538- let orders = orders. into_iter ( ) . map ( From :: from ) . collect :: < Result < _ , _ > > ( ) ?;
537+ let outputs = outputs. into_iter ( ) . map ( TryFrom :: try_from ) . collect :: < Result < _ , _ > > ( ) ? ;
538+ let orders = orders. into_iter ( ) . map ( TryFrom :: try_from ) . collect :: < Result < _ , _ > > ( ) ?;
539539 ActionType :: TransferAsset {
540540 network_id,
541541 burns : burns. into_iter ( ) . map ( From :: from) . collect ( ) ,
542542 inputs : inputs. into_iter ( ) . map ( From :: from) . collect ( ) ,
543- outputs : Result :: from_iter ( iter_outputs ) ? ,
543+ outputs,
544544 orders,
545545 metadata,
546546 approvals,
@@ -587,7 +587,7 @@ impl From<Action> for Result<ActionType, ConversionError> {
587587 output,
588588 approvals,
589589 } => {
590- let output_content = Result :: < AssetMintOutputType , FromHexError > :: from ( * output) ?;
590+ let output_content = AssetMintOutputType :: try_from ( * output) ?;
591591 ActionType :: IncreaseAssetSupply {
592592 network_id,
593593 shard_id,
@@ -617,7 +617,7 @@ impl From<Action> for Result<ActionType, ConversionError> {
617617 Some ( registrar) => Some ( registrar. try_into_address ( ) ?) ,
618618 None => None ,
619619 } ;
620- let output_content = Result :: < AssetMintOutputType , FromHexError > :: from ( * output) ?;
620+ let output_content = AssetMintOutputType :: try_from ( * output) ?;
621621 ActionType :: ComposeAsset {
622622 network_id,
623623 shard_id,
@@ -637,11 +637,11 @@ impl From<Action> for Result<ActionType, ConversionError> {
637637
638638 approvals,
639639 } => {
640- let iter_outputs = outputs. into_iter ( ) . map ( From :: from ) ;
640+ let outputs = outputs. into_iter ( ) . map ( TryFrom :: try_from ) . collect :: < Result < _ , _ > > ( ) ? ;
641641 ActionType :: DecomposeAsset {
642642 network_id,
643643 input : ( * input) . into ( ) ,
644- outputs : Result :: from_iter ( iter_outputs ) ? ,
644+ outputs,
645645 approvals,
646646 }
647647 }
0 commit comments