1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use crate::{serde_helper::vec_bytes, transaction::transaction_argument::TransactionArgument};
use move_core_types::{
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, TypeTag},
};
use serde::{Deserialize, Serialize};
use std::fmt;
pub use move_core_types::abi::{
ArgumentABI, ScriptABI, ScriptFunctionABI, TransactionScriptABI, TypeArgumentABI,
};
#[derive(Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct Script {
#[serde(with = "serde_bytes")]
code: Vec<u8>,
ty_args: Vec<TypeTag>,
args: Vec<TransactionArgument>,
}
impl Script {
pub fn new(code: Vec<u8>, ty_args: Vec<TypeTag>, args: Vec<TransactionArgument>) -> Self {
Script {
code,
ty_args,
args,
}
}
pub fn code(&self) -> &[u8] {
&self.code
}
pub fn ty_args(&self) -> &[TypeTag] {
&self.ty_args
}
pub fn args(&self) -> &[TransactionArgument] {
&self.args
}
pub fn into_inner(self) -> (Vec<u8>, Vec<TransactionArgument>) {
(self.code, self.args)
}
}
impl fmt::Debug for Script {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Script")
.field("code", &hex::encode(&self.code))
.field("ty_args", &self.ty_args)
.field("args", &self.args)
.finish()
}
}
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct ScriptFunction {
module: ModuleId,
function: Identifier,
ty_args: Vec<TypeTag>,
#[serde(with = "vec_bytes")]
args: Vec<Vec<u8>>,
}
impl ScriptFunction {
pub fn new(
module: ModuleId,
function: Identifier,
ty_args: Vec<TypeTag>,
args: Vec<Vec<u8>>,
) -> Self {
ScriptFunction {
module,
function,
ty_args,
args,
}
}
pub fn module(&self) -> &ModuleId {
&self.module
}
pub fn function(&self) -> &IdentStr {
&self.function
}
pub fn ty_args(&self) -> &[TypeTag] {
&self.ty_args
}
pub fn args(&self) -> &[Vec<u8>] {
&self.args
}
}