Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add codeHash to contract #234

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sealed class Transaction with _$Transaction implements Comparable<Transaction> {
@amountJsonConverter required final BigInt totalFees,
required final Message inMessage,
required final List<Message> outMessages,
required String boc,
}) = _Transaction;

factory Transaction.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mixin _$Transaction {
BigInt get totalFees => throw _privateConstructorUsedError;
Message get inMessage => throw _privateConstructorUsedError;
List<Message> get outMessages => throw _privateConstructorUsedError;
String get boc => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -59,7 +60,8 @@ abstract class $TransactionCopyWith<$Res> {
AccountStatus endStatus,
@amountJsonConverter BigInt totalFees,
Message inMessage,
List<Message> outMessages});
List<Message> outMessages,
String boc});

$TransactionIdCopyWith<$Res> get id;
$TransactionIdCopyWith<$Res>? get prevTransactionId;
Expand Down Expand Up @@ -90,6 +92,7 @@ class _$TransactionCopyWithImpl<$Res, $Val extends Transaction>
Object? totalFees = null,
Object? inMessage = null,
Object? outMessages = null,
Object? boc = null,
}) {
return _then(_value.copyWith(
id: null == id
Expand Down Expand Up @@ -136,6 +139,10 @@ class _$TransactionCopyWithImpl<$Res, $Val extends Transaction>
? _value.outMessages
: outMessages // ignore: cast_nullable_to_non_nullable
as List<Message>,
boc: null == boc
? _value.boc
: boc // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}

Expand Down Expand Up @@ -187,7 +194,8 @@ abstract class _$$TransactionImplCopyWith<$Res>
AccountStatus endStatus,
@amountJsonConverter BigInt totalFees,
Message inMessage,
List<Message> outMessages});
List<Message> outMessages,
String boc});

@override
$TransactionIdCopyWith<$Res> get id;
Expand Down Expand Up @@ -219,6 +227,7 @@ class __$$TransactionImplCopyWithImpl<$Res>
Object? totalFees = null,
Object? inMessage = null,
Object? outMessages = null,
Object? boc = null,
}) {
return _then(_$TransactionImpl(
id: null == id
Expand Down Expand Up @@ -265,6 +274,10 @@ class __$$TransactionImplCopyWithImpl<$Res>
? _value._outMessages
: outMessages // ignore: cast_nullable_to_non_nullable
as List<Message>,
boc: null == boc
? _value.boc
: boc // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
Expand All @@ -283,7 +296,8 @@ class _$TransactionImpl extends _Transaction {
required this.endStatus,
@amountJsonConverter required this.totalFees,
required this.inMessage,
required final List<Message> outMessages})
required final List<Message> outMessages,
required this.boc})
: _outMessages = outMessages,
super._();

Expand Down Expand Up @@ -322,9 +336,12 @@ class _$TransactionImpl extends _Transaction {
return EqualUnmodifiableListView(_outMessages);
}

@override
final String boc;

@override
String toString() {
return 'Transaction(id: $id, prevTransactionId: $prevTransactionId, createdAt: $createdAt, aborted: $aborted, exitCode: $exitCode, resultCode: $resultCode, origStatus: $origStatus, endStatus: $endStatus, totalFees: $totalFees, inMessage: $inMessage, outMessages: $outMessages)';
return 'Transaction(id: $id, prevTransactionId: $prevTransactionId, createdAt: $createdAt, aborted: $aborted, exitCode: $exitCode, resultCode: $resultCode, origStatus: $origStatus, endStatus: $endStatus, totalFees: $totalFees, inMessage: $inMessage, outMessages: $outMessages, boc: $boc)';
}

@override
Expand All @@ -351,7 +368,8 @@ class _$TransactionImpl extends _Transaction {
(identical(other.inMessage, inMessage) ||
other.inMessage == inMessage) &&
const DeepCollectionEquality()
.equals(other._outMessages, _outMessages));
.equals(other._outMessages, _outMessages) &&
(identical(other.boc, boc) || other.boc == boc));
}

@JsonKey(ignore: true)
Expand All @@ -368,7 +386,8 @@ class _$TransactionImpl extends _Transaction {
endStatus,
totalFees,
inMessage,
const DeepCollectionEquality().hash(_outMessages));
const DeepCollectionEquality().hash(_outMessages),
boc);

@JsonKey(ignore: true)
@override
Expand Down Expand Up @@ -396,7 +415,8 @@ abstract class _Transaction extends Transaction {
required final AccountStatus endStatus,
@amountJsonConverter required final BigInt totalFees,
required final Message inMessage,
required final List<Message> outMessages}) = _$TransactionImpl;
required final List<Message> outMessages,
required final String boc}) = _$TransactionImpl;
const _Transaction._() : super._();

factory _Transaction.fromJson(Map<String, dynamic> json) =
Expand Down Expand Up @@ -429,6 +449,8 @@ abstract class _Transaction extends Transaction {
@override
List<Message> get outMessages;
@override
String get boc;
@override
@JsonKey(ignore: true)
_$$TransactionImplCopyWith<_$TransactionImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/nekoton_bridge/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ nekoton = { git = "https://github.com/broxus/nekoton.git", features = [
"gql_transport",
"jrpc_transport",
"proto_transport",
"extended_models",
], rev = "d70dd09d4d482987541f1816fd3bce970710178c" }
nekoton-abi = { git = "https://github.com/broxus/nekoton.git", rev = "d70dd09d4d482987541f1816fd3bce970710178c" }
nekoton-utils = { git = "https://github.com/broxus/nekoton.git", rev = "d70dd09d4d482987541f1816fd3bce970710178c" }
Expand Down
21 changes: 18 additions & 3 deletions packages/nekoton_bridge/native/src/nekoton_wrapper/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::nekoton_wrapper::HandleError;
use nekoton::transport::models::RawContractState;
use nekoton_abi::MethodName;
use std::str::FromStr;
use ton_block::{Deserializable, MaybeDeserialize, Serializable};
use ton_block::{AccountStuff, Deserializable, MaybeDeserialize, Serializable};
use ton_types::SliceData;

pub mod abi_api;
Expand Down Expand Up @@ -249,13 +249,15 @@ pub fn make_full_contract_state(
&state.account.storage.state,
ton_block::AccountState::AccountActive { state_init: _ }
);
let account = state.account.clone();
let code_hash = get_code_hash(&account).handle_error()?;

Some(FullContractState {
balance: state.account.storage.balance.grams.as_u128().to_string(),
balance: account.storage.balance.grams.as_u128().to_string(),
gen_timings: state.timings,
last_transaction_id: Some(state.last_transaction_id),
is_deployed,
code_hash: None,
code_hash: Some(code_hash),
boc,
})
}
Expand All @@ -267,3 +269,16 @@ pub fn make_full_contract_state(
Some(state) => Ok(Some(serde_json::to_string(&state).handle_error()?)),
}
}

pub fn get_code_hash(account: &AccountStuff) -> anyhow::Result<String> {
match account.clone().storage.state {
ton_block::AccountState::AccountActive { state_init, .. } => {
let toc = state_init.code.as_ref().map(ton_types::serialize_toc);
match toc {
Some(t) => Ok(t.map(base64::encode).handle_error()?),
None => Err("WalletNotDeployed").handle_error()?,
}
}
_ => Err("WalletNotDeployed").handle_error()?,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::nekoton_wrapper::transport::models::{
AccountsList, RawContractStateHelper, TransactionsList,
};
use crate::nekoton_wrapper::{
helpers::make_full_contract_state, parse_address, parse_hash, HandleError,
helpers::{make_boc, make_full_contract_state},
parse_address, parse_hash, HandleError,
};
use async_trait::async_trait;
use duplicate::duplicate_item;
Expand Down Expand Up @@ -216,8 +217,9 @@ impl TransportBoxTrait for name {
let transactions = raw_transactions
.clone()
.into_iter()
.filter_map(|e| Transaction::try_from((e.hash, e.data)).ok())
.collect::<Vec<_>>();
.map(|e| convert_transaction_to_json(&Transaction::try_from((e.hash, e.data))?))
.collect::<anyhow::Result<Vec<_>>>();
let transactions = transactions?;

let continuation = raw_transactions.last().and_then(|e| {
(e.data.prev_trans_lt != 0).then_some(TransactionId {
Expand Down Expand Up @@ -260,7 +262,9 @@ impl TransportBoxTrait for name {

match transaction {
None => Ok(None),
Some(_) => Ok(Some(serde_json::to_string(&transaction).handle_error()?)),
Some(t) => Ok(Some(serde_json::to_string(&convert_transaction_to_json(
&t,
)?)?)),
}
}

Expand All @@ -279,7 +283,7 @@ impl TransportBoxTrait for name {
Some(t) => {
let trans = RawTransactionDef {
hash,
data: Transaction::try_from((t.hash, t.data))?,
data: convert_transaction_to_json(&Transaction::try_from((t.hash, t.data))?)?,
};
Ok(Some(serde_json::to_string(&trans).handle_error()?))
}
Expand Down Expand Up @@ -451,8 +455,9 @@ impl TransportBoxTrait for GqlTransportBox {
let transactions = raw_transactions
.clone()
.into_iter()
.filter_map(|e| Transaction::try_from((e.hash, e.data)).ok())
.collect::<Vec<_>>();
.map(|e| convert_transaction_to_json(&Transaction::try_from((e.hash, e.data))?))
.collect::<anyhow::Result<Vec<_>>>();
let transactions = transactions?;

let continuation = raw_transactions.last().and_then(|e| {
(e.data.prev_trans_lt != 0).then_some(TransactionId {
Expand Down Expand Up @@ -494,7 +499,9 @@ impl TransportBoxTrait for GqlTransportBox {
.handle_error()?;
match transaction {
None => Ok(None),
Some(_) => Ok(Some(serde_json::to_string(&transaction).handle_error()?)),
Some(t) => Ok(Some(serde_json::to_string(&convert_transaction_to_json(
&t,
)?)?)),
}
}

Expand All @@ -513,7 +520,7 @@ impl TransportBoxTrait for GqlTransportBox {
Some(t) => {
let trans = RawTransactionDef {
hash,
data: Transaction::try_from((t.hash, t.data))?,
data: convert_transaction_to_json(&Transaction::try_from((t.hash, t.data))?)?,
};
Ok(Some(serde_json::to_string(&trans).handle_error()?))
}
Expand Down Expand Up @@ -608,3 +615,20 @@ impl TransportBoxTrait for GqlTransportBox {
Ok(next_block_id)
}
}

pub fn convert_transaction_to_json(t: &Transaction) -> anyhow::Result<serde_json::Value> {
Ok(serde_json::json!({
"id" : t.id,
"prevTransId": t.prev_trans_id,
"createdAt": t.created_at,
"aborted": t.aborted,
"exitCode": t.exit_code,
"resultCode": t.result_code,
"origStatus":t.orig_status,
"endStatus":t.end_status,
"totalFees" : t.total_fees.to_string(),
"inMessage": t.in_msg,
"outMessages": t.out_msgs,
"boc": make_boc(&t.raw)?,
}))
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use nekoton::{
core::models::{Transaction, TransactionsBatchInfo},
core::models::TransactionsBatchInfo,
transport::models::{ExistingContract, RawContractState},
};
use nekoton_abi::{GenTimings, LastTransactionId, TransactionId};
Expand Down Expand Up @@ -37,7 +37,8 @@ pub struct FullContractState {

#[derive(Serialize)]
pub struct TransactionsList {
pub transactions: Vec<Transaction>,
// item=Transaction, to get it use `convert_transaction_to_json`
pub transactions: Vec<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub continuation: Option<TransactionId>,
pub info: Option<TransactionsBatchInfo>,
Expand All @@ -58,7 +59,9 @@ pub struct AccountsList {
pub struct RawTransactionDef {
#[serde(with = "serde_hex_array")]
pub hash: UInt256,
pub data: Transaction,

// data=Transaction, to get it use `convert_transaction_to_json`
pub data: serde_json::Value,
}

#[derive(Serialize)]
Expand Down
Loading