Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Tron signing #63

Closed
wants to merge 21 commits into from
Closed

Tron signing #63

wants to merge 21 commits into from

Conversation

OlegGordiichuk
Copy link
Contributor

Hello it is my first implementation of the network.

Could you take a look at implementation before I add unit tests ?

Document that I was using during implementation.

https://github.com/tronprotocol/Documentation/blob/master/TRX/Tron-overview.md#103-signature

Copy link
Contributor

@vikmeup vikmeup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests?

private let toAddress: Data
private let amount: Int64

init(ownerAddress: Data, toAddress: Data, amount: Int64) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you pass TronAddress?

let rawData = TronTransactionRawDataBuilder()
.contract(contract)
.timestamp(Date().currentTimeMilliseconds)
.expiration(blockHeader.rawData.timestamp + 10 * 60 * 60 * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this customizable from the app side? so you pass this value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if builder pattern is suitable here, most of the properties are primitive types...

struct TransferAssetContract: TronTransactionContract {

private let assetName: Data
private let ownerAddress: Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use TronAddress


struct TransferAssetContract: TronTransactionContract {

private let assetName: Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets name as String?


extension Protocol_Transaction {
private func hash() -> Data {
return Crypto.sha256(rawData.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a property.

extension Date {
var currentTimeMilliseconds: Int64 {
let now = timeIntervalSince1970
return Int64(now * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just Int64(timeIntervalSince1970 * 1000)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal opinion, currentTimeMilliseconds is a bit long, like good old objc variable naming

@@ -53,6 +53,9 @@
/// Computes the SHA256 hash of the SHA256 hash of the data.
+ (nonnull NSData *)sha256sha256:(nonnull NSData *)data;

/// Computes the SHA256 hash of the data.
+ (nonnull NSData *)sha256:(nonnull NSData *)data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is also hash() which is the same thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikmeup not exactly the same, hash() is too general, how about rename to keccak256 or something similar

@@ -0,0 +1,4581 @@
// DO NOT EDIT.
Copy link
Contributor

@vikmeup vikmeup Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you exclude files from the commit? we should run script to generate them instead from original protobuf

Copy link
Contributor

@hewigovens hewigovens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few comments, how large is the new introduced SwiftProtobuf.framework?

@@ -53,6 +53,9 @@
/// Computes the SHA256 hash of the SHA256 hash of the data.
+ (nonnull NSData *)sha256sha256:(nonnull NSData *)data;

/// Computes the SHA256 hash of the data.
+ (nonnull NSData *)sha256:(nonnull NSData *)data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikmeup not exactly the same, hash() is too general, how about rename to keccak256 or something similar

extension Date {
var currentTimeMilliseconds: Int64 {
let now = timeIntervalSince1970
return Int64(now * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal opinion, currentTimeMilliseconds is a bit long, like good old objc variable naming


import UIKit

extension Protocol_Transaction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protocol_Transaction is generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hewigovens yes it is generated by protobuf.


enum TronTransactionError: Error {
case blockHeaderHeight
case blockHeaderRawData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe LocalizedError? block height/raw data seems not like a error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it makes sense

let rawData = TronTransactionRawDataBuilder()
.contract(contract)
.timestamp(Date().currentTimeMilliseconds)
.expiration(blockHeader.rawData.timestamp + 10 * 60 * 60 * 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if builder pattern is suitable here, most of the properties are primitive types...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants