SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
5.9 KB · 163 lines swift
Raw Blame History
1import WalletCoreC2import Foundation3// SPDX-License-Identifier: Apache-2.04//5// Copyright © 2017 Trust Wallet.6//7// This is a GENERATED FILE, changes made here WILL BE LOST.8//910import Foundation1112/// Represents Ethereum ABI value13public struct EthereumAbiValue {1415    /// Encode a bool according to Ethereum ABI, into 32 bytes.  Values are padded by 0 on the left, unless specified otherwise16    ///17    /// - Parameter value: a boolean value18    /// - Returns: Encoded value stored in a block of data19    public static func encodeBool(value: Bool) -> Data {20        return TWDataNSData(TWEthereumAbiValueEncodeBool(value))21    }2223    /// Encode a int32 according to Ethereum ABI, into 32 bytes. Values are padded by 0 on the left, unless specified otherwise24    ///25    /// - Parameter value: a int32 value26    /// - Returns: Encoded value stored in a block of data27    public static func encodeInt32(value: Int32) -> Data {28        return TWDataNSData(TWEthereumAbiValueEncodeInt32(value))29    }3031    /// Encode a uint32 according to Ethereum ABI, into 32 bytes.  Values are padded by 0 on the left, unless specified otherwise32    ///33    /// - Parameter value: a uint32 value34    /// - Returns: Encoded value stored in a block of data35    public static func encodeUInt32(value: UInt32) -> Data {36        return TWDataNSData(TWEthereumAbiValueEncodeUInt32(value))37    }3839    /// Encode a int256 according to Ethereum ABI, into 32 bytes.  Values are padded by 0 on the left, unless specified otherwise40    ///41    /// - Parameter value: a int256 value stored in a block of data42    /// - Returns: Encoded value stored in a block of data43    public static func encodeInt256(value: Data) -> Data {44        let valueData = TWDataCreateWithNSData(value)45        defer {46            TWDataDelete(valueData)47        }48        return TWDataNSData(TWEthereumAbiValueEncodeInt256(valueData))49    }5051    /// Encode an int256 according to Ethereum ABI, into 32 bytes.  Values are padded by 0 on the left, unless specified otherwise52    ///53    /// - Parameter value: a int256 value stored in a block of data54    /// - Returns: Encoded value stored in a block of data55    public static func encodeUInt256(value: Data) -> Data {56        let valueData = TWDataCreateWithNSData(value)57        defer {58            TWDataDelete(valueData)59        }60        return TWDataNSData(TWEthereumAbiValueEncodeUInt256(valueData))61    }6263    /// Encode an address according to Ethereum ABI, 20 bytes of the address.64    ///65    /// - Parameter value: an address value stored in a block of data66    /// - Returns: Encoded value stored in a block of data67    public static func encodeAddress(value: Data) -> Data {68        let valueData = TWDataCreateWithNSData(value)69        defer {70            TWDataDelete(valueData)71        }72        return TWDataNSData(TWEthereumAbiValueEncodeAddress(valueData))73    }7475    /// Encode a string according to Ethereum ABI by encoding its hash.76    ///77    /// - Parameter value: a string value78    /// - Returns: Encoded value stored in a block of data79    public static func encodeString(value: String) -> Data {80        let valueString = TWStringCreateWithNSString(value)81        defer {82            TWStringDelete(valueString)83        }84        return TWDataNSData(TWEthereumAbiValueEncodeString(valueString))85    }8687    /// Encode a number of bytes, up to 32 bytes, padded on the right.  Longer arrays are truncated.88    ///89    /// - Parameter value: bunch of bytes90    /// - Returns: Encoded value stored in a block of data91    public static func encodeBytes(value: Data) -> Data {92        let valueData = TWDataCreateWithNSData(value)93        defer {94            TWDataDelete(valueData)95        }96        return TWDataNSData(TWEthereumAbiValueEncodeBytes(valueData))97    }9899    /// Encode a dynamic number of bytes by encoding its hash100    ///101    /// - Parameter value: bunch of bytes102    /// - Returns: Encoded value stored in a block of data103    public static func encodeBytesDyn(value: Data) -> Data {104        let valueData = TWDataCreateWithNSData(value)105        defer {106            TWDataDelete(valueData)107        }108        return TWDataNSData(TWEthereumAbiValueEncodeBytesDyn(valueData))109    }110111    /// Decodes input data (bytes longer than 32 will be truncated) as uint256112    ///113    /// - Parameter input: Data to be decoded114    /// - Returns: Non-null decoded string value115    public static func decodeUInt256(input: Data) -> String {116        let inputData = TWDataCreateWithNSData(input)117        defer {118            TWDataDelete(inputData)119        }120        return TWStringNSString(TWEthereumAbiValueDecodeUInt256(inputData))121    }122123    /// Decode an arbitrary type, return value as string124    ///125    /// - Parameter input: Data to be decoded126    /// - Parameter type: the underlying type that need to be decoded127    /// - Returns: Non-null decoded string value128    public static func decodeValue(input: Data, type: String) -> String {129        let inputData = TWDataCreateWithNSData(input)130        defer {131            TWDataDelete(inputData)132        }133        let typeString = TWStringCreateWithNSString(type)134        defer {135            TWStringDelete(typeString)136        }137        return TWStringNSString(TWEthereumAbiValueDecodeValue(inputData, typeString))138    }139140    /// Decode an array of given simple types.  Return a '\n'-separated string of elements141    ///142    /// - Parameter input: Data to be decoded143    /// - Parameter type: the underlying type that need to be decoded144    /// - Returns: Non-null decoded string value145    public static func decodeArray(input: Data, type: String) -> String {146        let inputData = TWDataCreateWithNSData(input)147        defer {148            TWDataDelete(inputData)149        }150        let typeString = TWStringCreateWithNSString(type)151        defer {152            TWStringDelete(typeString)153        }154        return TWStringNSString(TWEthereumAbiValueDecodeArray(inputData, typeString))155    }156157158    init() {159    }160161162}163