Skip to content

Commit

Permalink
fix: fixed protobuf update errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Feb 12, 2021
1 parent c124f00 commit d96c6cf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
3 changes: 2 additions & 1 deletion contract_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (builder ContractUpdateTransaction) SetExpirationTime(expiration time.Time)

// SetContractMemo sets the memo associated with the contract (max 100 bytes)
func (builder ContractUpdateTransaction) SetContractMemo(memo string) ContractUpdateTransaction {
builder.pb.Memo = memo
builder.pb.MemoField = &proto.ContractUpdateTransactionBody_Memo{memo}

return builder
}

Expand Down
8 changes: 6 additions & 2 deletions token_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func (builder TokenCreateTransaction) SetFreezeDefault(freeze bool) TokenCreateT

// The epoch second at which the token should expire; if an auto-renew account and period are specified, this is coerced to the current epoch second plus the autoRenewPeriod
func (builder TokenCreateTransaction) SetExpirationTime(expirationTime uint64) TokenCreateTransaction {
builder.pb.Expiry = expirationTime
builder.pb.Expiry = &proto.Timestamp{
Seconds: time.Now().Unix() + int64(expirationTime),
}
return builder
}

Expand All @@ -104,7 +106,9 @@ func (builder TokenCreateTransaction) SetAutoRenewAccountID(autoRenewAccountID A

// The interval at which the auto-renew account will be charged to extend the token's expiry
func (builder TokenCreateTransaction) SetAutoRenewPeriod(autoRenewPeriod uint64) TokenCreateTransaction {
builder.pb.AutoRenewPeriod = autoRenewPeriod
builder.pb.AutoRenewPeriod = &proto.Duration{
Seconds: time.Now().Unix() + int64(autoRenewPeriod),
}
return builder
}

Expand Down
6 changes: 3 additions & 3 deletions token_info_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (builder *TokenInfoQuery) Execute(client *Client) (TokenInfo, error) {
SupplyKey: supplyKey,
TokenFreezeStatus: freezeStatus,
TokenKycStatus: kycStatus,
IsDeleted: resp.GetTokenGetInfo().TokenInfo.IsDeleted,
IsDeleted: resp.GetTokenGetInfo().TokenInfo.Deleted,
AutoRenewAccount: accountIDFromProto(resp.GetTokenGetInfo().TokenInfo.AutoRenewAccount),
AutoRenewPeriod: resp.GetTokenGetInfo().TokenInfo.AutoRenewPeriod,
ExpirationTime: resp.GetTokenGetInfo().TokenInfo.Expiry,
AutoRenewPeriod: uint64(resp.GetTokenGetInfo().TokenInfo.AutoRenewPeriod.Seconds),
ExpirationTime: uint64(resp.GetTokenGetInfo().TokenInfo.Expiry.Seconds),
}, nil
}

Expand Down
8 changes: 6 additions & 2 deletions token_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (builder TokenUpdateTransaction) SetSupplyKey(supplykey PublicKey) TokenUpd

// The new expiry time of the token. Expiry can be updated even if admin key is not set. If the provided expiry is earlier than the current token expiry, transaction wil resolve to INVALID_EXPIRATION_TIME
func (builder TokenUpdateTransaction) SetExpirationTime(expirationTime uint64) TokenUpdateTransaction {
builder.pb.Expiry = expirationTime
builder.pb.Expiry = &proto.Timestamp{
Seconds: time.Now().Unix() + int64(expirationTime),
}
return builder
}

Expand All @@ -90,7 +92,9 @@ func (builder TokenUpdateTransaction) SetAutoRenewAccountID(autoRenewAccountID A

// The new interval at which the auto-renew account will be charged to extend the token's expiry.
func (builder TokenUpdateTransaction) SetAutoRenewPeriod(autoRenewPeriod uint64) TokenUpdateTransaction {
builder.pb.AutoRenewPeriod = autoRenewPeriod
builder.pb.AutoRenewPeriod = &proto.Duration{
Seconds: time.Now().Unix() + int64(autoRenewPeriod),
}
return builder
}

Expand Down
30 changes: 28 additions & 2 deletions transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type TransactionReceipt struct {
tokenID *TokenID
consensusTopicSequenceNumber uint64
consensusTopicRunningHash []byte
newTotalSupply uint64
scheduleID *ScheduleID
}

// GetFileID returns the FileID associated with the receipt's transaction or else panics no FileID exists
Expand Down Expand Up @@ -126,6 +128,22 @@ func (receipt TransactionReceipt) TryGetConsensusTopicRunningHash() ([]byte, err
return receipt.consensusTopicRunningHash, nil
}

func (receipt TransactionReceipt) GetNewTotalSupply() uint64 {
return receipt.newTotalSupply
}

func (receipt TransactionReceipt) GetSchedule() ScheduleID {
return *receipt.scheduleID
}

func (receipt TransactionReceipt) TryGetScheduleID() (ScheduleID, error) {
if receipt.scheduleID == nil {
return ScheduleID{}, fmt.Errorf("no schedule id exists on this receipt")
}

return receipt.GetSchedule(), nil
}

func transactionReceiptFromResponse(response *proto.Response) TransactionReceipt {
return transactionReceiptFromProto(response.GetTransactionGetReceipt().Receipt)
}
Expand Down Expand Up @@ -156,11 +174,17 @@ func transactionReceiptFromProto(pb *proto.TransactionReceipt) TransactionReceip
}

var tokenID *TokenID
if pb.TokenId != nil {
tokenIDValue := tokenIDFromProto(pb.TokenId)
if pb.TokenID != nil {
tokenIDValue := tokenIDFromProto(pb.TokenID)
tokenID = &tokenIDValue
}

var scheduleID *ScheduleID
if pb.ScheduleID != nil {
scheduleIDValue := scheduleIDFromProto(pb.ScheduleID)
scheduleID = &scheduleIDValue
}

return TransactionReceipt{
Status: Status(pb.Status),
accountID: accountID,
Expand All @@ -170,5 +194,7 @@ func transactionReceiptFromProto(pb *proto.TransactionReceipt) TransactionReceip
consensusTopicID: consensusTopicID,
consensusTopicSequenceNumber: pb.TopicSequenceNumber,
consensusTopicRunningHash: pb.TopicRunningHash,
newTotalSupply: pb.NewTotalSupply,
scheduleID: scheduleID,
}
}

0 comments on commit d96c6cf

Please sign in to comment.