pyonear 0.2.0

Python bindings for NEAR Rust primitives.
Documentation
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
use crate::{
    account_id::AccountId, add_classes, add_union, add_union_to_module, hash_enum, vec_type_object,
};
use derive_more::From;
use near_vm_errors::{
    CacheError as CacheErrorOriginal, CompilationError as CompilationErrorOriginal,
    FunctionCallErrorSer as FunctionCallErrorSerOriginal, HostError as HostErrorOriginal,
    MethodResolveError as MethodResolveErrorOriginal, PrepareError as PrepareErrorOriginal,
    WasmTrap as WasmTrapOriginal,
};
use pyo3::types::PyString;
use pyo3::{prelude::*, types::PyType};
use serde::{Deserialize, Serialize};
use solders_macros::{enum_original_mapping, EnumIntoPy};
use std::fmt::{self};

macro_rules! quick_struct_vm {
    ($name:ident, $doc:literal, $($element:ident: $ty:ty),*) => {
        $crate::quick_struct!(
            $name,
            $doc,
            "pyonear.error.vm",
            $($element:$ty),*
        );
    };
}

macro_rules! quick_struct_vm_method_name {
    ($name:ident, $doc:literal) => {
        quick_struct_vm!($name, $doc, method_name: String);
    };
}

macro_rules! quick_struct_vm_msg {
    ($name:ident, $doc:literal) => {
        quick_struct_vm!($name, $doc, msg: String);
    };
}
macro_rules! quick_struct_vm_length_limit {
    ($name:ident, $doc:literal) => {
        $crate::quick_struct_length_limit!($name, $doc, "pyonear.error.vm");
    };
}
macro_rules! quick_struct_vm_size_limit {
    ($name:ident, $doc:literal) => {
        $crate::quick_struct_size_limit!($name, $doc, "pyonear.error.vm");
    };
}

macro_rules! quick_struct_vm_u64 {
    ($name:ident, $doc:literal, $elem:ident) => {
        quick_struct_vm!($name, $doc, $elem: u64);
    };
}

quick_struct_vm_msg!(LinkError, "Wasm binary env link error");

/// Serializable version of ``FunctionCallError``.
#[derive(PartialEq, Eq, Clone, Debug, FromPyObject, EnumIntoPy)]
pub enum FunctionCallErrorSer {
    Fieldless(FunctionCallErrorSerFieldless),
    CompilationError(CompilationError),
    LinkError(LinkError),
    MethodResolveError(MethodResolveError),
    WasmTrap(WasmTrap),
    HostError(HostError),
    ExecutionError(String),
}

impl From<FunctionCallErrorSer> for FunctionCallErrorSerOriginal {
    fn from(e: FunctionCallErrorSer) -> Self {
        type E = FunctionCallErrorSer;
        match e {
            E::Fieldless(f) => match f {
                FunctionCallErrorSerFieldless::WasmUnknownError => Self::WasmUnknownError,
                FunctionCallErrorSerFieldless::_EVMError => Self::_EVMError,
            },
            E::CompilationError(x) => Self::CompilationError(x.into()),
            E::LinkError(x) => Self::LinkError { msg: x.msg },
            E::MethodResolveError(x) => Self::MethodResolveError(x.into()),
            E::WasmTrap(x) => Self::WasmTrap(x.into()),
            E::HostError(x) => Self::HostError(x.into()),
            E::ExecutionError(x) => Self::ExecutionError(x),
        }
    }
}

impl From<FunctionCallErrorSerOriginal> for FunctionCallErrorSer {
    fn from(e: FunctionCallErrorSerOriginal) -> Self {
        type E = FunctionCallErrorSerOriginal;
        match e {
            E::WasmUnknownError => Self::Fieldless(FunctionCallErrorSerFieldless::WasmUnknownError),
            E::_EVMError => Self::Fieldless(FunctionCallErrorSerFieldless::_EVMError),
            E::CompilationError(x) => Self::CompilationError(x.into()),
            E::LinkError { msg } => Self::LinkError(LinkError { msg }),
            E::MethodResolveError(x) => Self::MethodResolveError(x.into()),
            E::WasmTrap(x) => Self::WasmTrap(x.into()),
            E::HostError(x) => Self::HostError(x.into()),
            E::ExecutionError(x) => Self::ExecutionError(x),
        }
    }
}

#[pyclass(module = "pyonear.error.vm")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum FunctionCallErrorSerFieldless {
    WasmUnknownError,
    _EVMError,
}
hash_enum!(FunctionCallErrorSerFieldless);

#[pyclass(module = "pyonear.error.vm")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum CacheErrorFieldless {
    ReadError,
    WriteError,
    DeserializationError,
}
hash_enum!(CacheErrorFieldless);

quick_struct_vm!(SerializationError, "", hash: [u8; 32]);

#[derive(PartialEq, Eq, Clone, Debug, FromPyObject, From)]
pub enum CacheError {
    Fieldless(CacheErrorFieldless),
    SerializationError(SerializationError),
}

impl From<CacheError> for CacheErrorOriginal {
    fn from(e: CacheError) -> Self {
        match e {
            CacheError::Fieldless(f) => match f {
                CacheErrorFieldless::ReadError => Self::ReadError,
                CacheErrorFieldless::WriteError => Self::WriteError,
                CacheErrorFieldless::DeserializationError => Self::DeserializationError,
            },
            CacheError::SerializationError(s) => Self::SerializationError { hash: s.hash },
        }
    }
}

impl From<CacheErrorOriginal> for CacheError {
    fn from(e: CacheErrorOriginal) -> Self {
        match e {
            CacheErrorOriginal::ReadError => Self::Fieldless(CacheErrorFieldless::ReadError),
            CacheErrorOriginal::WriteError => Self::Fieldless(CacheErrorFieldless::WriteError),
            CacheErrorOriginal::DeserializationError => {
                Self::Fieldless(CacheErrorFieldless::DeserializationError)
            }
            CacheErrorOriginal::SerializationError { hash } => {
                Self::SerializationError(SerializationError { hash })
            }
        }
    }
}

/// A kind of a trap happened during execution of a binary
#[pyclass(module = "pyonear.error.vm")]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[enum_original_mapping(WasmTrapOriginal)]
pub enum WasmTrap {
    /// An `unreachable` opcode was executed.
    Unreachable,
    /// Call indirect incorrect signature trap.
    IncorrectCallIndirectSignature,
    /// Memory out of bounds trap.
    MemoryOutOfBounds,
    /// Call indirect out of bounds trap.
    CallIndirectOOB,
    /// An arithmetic exception, e.g. divided by zero.
    IllegalArithmetic,
    /// Misaligned atomic access trap.
    MisalignedAtomicAccess,
    /// Indirect call to null.
    IndirectCallToNull,
    /// Stack overflow.
    StackOverflow,
    /// Generic trap.
    GenericTrap,
}
hash_enum!(WasmTrap);

/// Import/export resolve error
#[pyclass(module = "pyonear.error.vm")]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[enum_original_mapping(MethodResolveErrorOriginal)]
pub enum MethodResolveError {
    MethodEmptyName,
    MethodNotFound,
    MethodInvalidSignature,
}
hash_enum!(MethodResolveError);

/// Wasm compilation error
#[derive(PartialEq, Eq, Clone, Debug, FromPyObject, From, EnumIntoPy)]
pub enum CompilationError {
    CodeDoesNotExist(CodeDoesNotExist),
    PrepareError(PrepareError),
    WasmerCompileError(WasmerCompileError),
    UnsupportedCompiler(UnsupportedCompiler),
}

impl From<CompilationError> for CompilationErrorOriginal {
    fn from(e: CompilationError) -> Self {
        type E = CompilationError;
        match e {
            E::CodeDoesNotExist(x) => Self::CodeDoesNotExist {
                account_id: x.account_id.into(),
            },
            E::PrepareError(x) => Self::PrepareError(x.into()),
            E::WasmerCompileError(x) => Self::WasmerCompileError { msg: x.msg },
            E::UnsupportedCompiler(x) => Self::UnsupportedCompiler { msg: x.msg },
        }
    }
}

impl From<CompilationErrorOriginal> for CompilationError {
    fn from(e: CompilationErrorOriginal) -> Self {
        type E = CompilationErrorOriginal;
        match e {
            E::CodeDoesNotExist { account_id } => Self::CodeDoesNotExist(CodeDoesNotExist {
                account_id: account_id.into(),
            }),
            E::PrepareError(x) => Self::PrepareError(x.into()),
            E::WasmerCompileError { msg } => Self::WasmerCompileError(WasmerCompileError { msg }),
            E::UnsupportedCompiler { msg } => {
                Self::UnsupportedCompiler(UnsupportedCompiler { msg })
            }
        }
    }
}

quick_struct_vm!(CodeDoesNotExist, "", account_id: AccountId);
quick_struct_vm_msg!(WasmerCompileError, "");
quick_struct_vm_msg!(UnsupportedCompiler, "");

#[pyclass(module = "pyonear.error.vm")]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[enum_original_mapping(PrepareErrorOriginal)]
/// Error that can occur while preparing or executing Wasm smart-contract.
pub enum PrepareError {
    /// Error happened while serializing the module.
    Serialization,
    /// Error happened while deserializing the module.
    Deserialization,
    /// Internal memory declaration has been found in the module.
    InternalMemoryDeclared,
    /// Gas instrumentation failed.
    ///
    /// This most likely indicates the module isn't valid.
    GasInstrumentation,
    /// Stack instrumentation failed.
    ///
    /// This  most likely indicates the module isn't valid.
    StackHeightInstrumentation,
    /// Error happened during instantiation.
    ///
    /// This might indicate that `start` function trapped, or module isn't
    /// instantiable and/or unlinkable.
    Instantiate,
    /// Error creating memory.
    Memory,
}
hash_enum!(PrepareError);

#[derive(PartialEq, Eq, Clone, Debug, FromPyObject, From, EnumIntoPy)]
pub enum HostError {
    Fieldless(HostErrorFieldless),
    GuestPanic(GuestPanic),
    InvalidPromiseIndex(InvalidPromiseIndex),
    InvalidPromiseResultIndex(InvalidPromiseResultIndex),
    InvalidRegisterId(InvalidRegisterId),
    IteratorWasInvalidated(IteratorWasInvalidated),
    InvalidReceiptIndex(InvalidReceiptIndex),
    InvalidIteratorIndex(InvalidIteratorIndex),
    ProhibitedInView(ProhibitedInView),
    NumberOfLogsExceeded(NumberOfLogsExceeded),
    KeyLengthExceeded(KeyLengthExceeded),
    ValueLengthExceeded(ValueLengthExceeded),
    TotalLogLengthExceeded(TotalLogLengthExceeded),
    NumberPromisesExceeded(NumberPromisesExceeded),
    NumberInputDataDependenciesExceeded(NumberInputDataDependenciesExceeded),
    ReturnedValueLengthExceeded(ReturnedValueLengthExceeded),
    ContractSizeExceeded(ContractSizeExceeded),
    Deprecated(Deprecated),
    ECRecoverError(ECRecoverError),
    Ed25519VerifyInvalidInput(Ed25519VerifyInvalidInput),
    AltBn128InvalidInput(AltBn128InvalidInput),
}

impl From<HostError> for HostErrorOriginal {
    fn from(h: HostError) -> Self {
        type H = HostError;
        match h {
            H::Fieldless(f) => match f {
                HostErrorFieldless::BadUTF16 => Self::BadUTF16,
                HostErrorFieldless::BadUTF8 => Self::BadUTF8,
                HostErrorFieldless::GasExceeded => Self::GasExceeded,
                HostErrorFieldless::GasLimitExceeded => Self::GasLimitExceeded,
                HostErrorFieldless::BalanceExceeded => Self::BalanceExceeded,
                HostErrorFieldless::EmptyMethodName => Self::EmptyMethodName,
                HostErrorFieldless::IntegerOverflow => Self::IntegerOverflow,
                HostErrorFieldless::CannotAppendActionToJointPromise => {
                    Self::CannotAppendActionToJointPromise
                }
                HostErrorFieldless::CannotReturnJointPromise => Self::CannotReturnJointPromise,
                HostErrorFieldless::MemoryAccessViolation => Self::MemoryAccessViolation,
                HostErrorFieldless::InvalidAccountId => Self::InvalidAccountId,
                HostErrorFieldless::InvalidMethodName => Self::InvalidMethodName,
                HostErrorFieldless::InvalidPublicKey => Self::InvalidPublicKey,
            },
            H::GuestPanic(x) => Self::GuestPanic {
                panic_msg: x.panic_msg,
            },
            H::InvalidPromiseIndex(x) => Self::InvalidPromiseIndex {
                promise_idx: x.promise_idx,
            },
            H::InvalidPromiseResultIndex(x) => Self::InvalidPromiseResultIndex {
                result_idx: x.result_idx,
            },
            H::InvalidRegisterId(x) => Self::InvalidRegisterId {
                register_id: x.register_id,
            },
            H::IteratorWasInvalidated(x) => Self::IteratorWasInvalidated {
                iterator_index: x.iterator_index,
            },
            H::InvalidReceiptIndex(x) => Self::InvalidReceiptIndex {
                receipt_index: x.receipt_index,
            },
            H::InvalidIteratorIndex(x) => Self::InvalidIteratorIndex {
                iterator_index: x.iterator_index,
            },
            H::ProhibitedInView(x) => Self::ProhibitedInView {
                method_name: x.method_name,
            },
            H::NumberOfLogsExceeded(x) => Self::NumberOfLogsExceeded { limit: x.limit },
            H::KeyLengthExceeded(x) => Self::KeyLengthExceeded {
                length: x.length,
                limit: x.limit,
            },
            H::ValueLengthExceeded(x) => Self::ValueLengthExceeded {
                length: x.length,
                limit: x.limit,
            },
            H::TotalLogLengthExceeded(x) => Self::TotalLogLengthExceeded {
                length: x.length,
                limit: x.limit,
            },
            H::NumberPromisesExceeded(x) => Self::NumberPromisesExceeded {
                number_of_promises: x.number_of_promises,
                limit: x.limit,
            },
            H::NumberInputDataDependenciesExceeded(x) => {
                Self::NumberInputDataDependenciesExceeded {
                    number_of_input_data_dependencies: x.number_of_input_data_dependencies,
                    limit: x.limit,
                }
            }
            H::ReturnedValueLengthExceeded(x) => Self::ReturnedValueLengthExceeded {
                length: x.length,
                limit: x.limit,
            },
            H::ContractSizeExceeded(x) => Self::ContractSizeExceeded {
                size: x.size,
                limit: x.limit,
            },
            H::Deprecated(x) => Self::Deprecated {
                method_name: x.method_name,
            },
            H::ECRecoverError(x) => Self::ECRecoverError { msg: x.msg },
            H::AltBn128InvalidInput(x) => Self::AltBn128InvalidInput { msg: x.msg },
            H::Ed25519VerifyInvalidInput(x) => Self::Ed25519VerifyInvalidInput { msg: x.msg },
        }
    }
}

impl From<HostErrorOriginal> for HostError {
    fn from(h: HostErrorOriginal) -> Self {
        type H = HostErrorOriginal;
        match h {
            H::BadUTF16 => Self::Fieldless(HostErrorFieldless::BadUTF16),
            H::BadUTF8 => Self::Fieldless(HostErrorFieldless::BadUTF8),
            H::GasExceeded => Self::Fieldless(HostErrorFieldless::GasExceeded),
            H::GasLimitExceeded => Self::Fieldless(HostErrorFieldless::GasLimitExceeded),
            H::BalanceExceeded => Self::Fieldless(HostErrorFieldless::BalanceExceeded),
            H::EmptyMethodName => Self::Fieldless(HostErrorFieldless::EmptyMethodName),
            H::IntegerOverflow => Self::Fieldless(HostErrorFieldless::IntegerOverflow),
            H::CannotAppendActionToJointPromise => {
                Self::Fieldless(HostErrorFieldless::CannotAppendActionToJointPromise)
            }
            H::CannotReturnJointPromise => {
                Self::Fieldless(HostErrorFieldless::CannotReturnJointPromise)
            }
            H::MemoryAccessViolation => Self::Fieldless(HostErrorFieldless::MemoryAccessViolation),
            H::InvalidAccountId => Self::Fieldless(HostErrorFieldless::InvalidAccountId),
            H::InvalidMethodName => Self::Fieldless(HostErrorFieldless::InvalidMethodName),
            H::InvalidPublicKey => Self::Fieldless(HostErrorFieldless::InvalidPublicKey),
            H::GuestPanic { panic_msg } => Self::GuestPanic(GuestPanic { panic_msg }),
            H::InvalidPromiseIndex { promise_idx } => {
                Self::InvalidPromiseIndex(InvalidPromiseIndex { promise_idx })
            }
            H::InvalidPromiseResultIndex { result_idx } => {
                Self::InvalidPromiseResultIndex(InvalidPromiseResultIndex { result_idx })
            }
            H::InvalidRegisterId { register_id } => {
                Self::InvalidRegisterId(InvalidRegisterId { register_id })
            }
            H::IteratorWasInvalidated { iterator_index } => {
                Self::IteratorWasInvalidated(IteratorWasInvalidated { iterator_index })
            }
            H::InvalidReceiptIndex { receipt_index } => {
                Self::InvalidReceiptIndex(InvalidReceiptIndex { receipt_index })
            }
            H::InvalidIteratorIndex { iterator_index } => {
                Self::InvalidIteratorIndex(InvalidIteratorIndex { iterator_index })
            }
            H::ProhibitedInView { method_name } => {
                Self::ProhibitedInView(ProhibitedInView { method_name })
            }
            H::NumberOfLogsExceeded { limit } => {
                Self::NumberOfLogsExceeded(NumberOfLogsExceeded { limit })
            }
            H::KeyLengthExceeded { length, limit } => {
                Self::KeyLengthExceeded(KeyLengthExceeded { length, limit })
            }
            H::ValueLengthExceeded { length, limit } => {
                Self::ValueLengthExceeded(ValueLengthExceeded { length, limit })
            }
            H::TotalLogLengthExceeded { length, limit } => {
                Self::TotalLogLengthExceeded(TotalLogLengthExceeded { length, limit })
            }
            H::NumberPromisesExceeded {
                number_of_promises,
                limit,
            } => Self::NumberPromisesExceeded(NumberPromisesExceeded {
                number_of_promises,
                limit,
            }),
            H::NumberInputDataDependenciesExceeded {
                number_of_input_data_dependencies,
                limit,
            } => Self::NumberInputDataDependenciesExceeded(NumberInputDataDependenciesExceeded {
                number_of_input_data_dependencies,
                limit,
            }),
            H::ReturnedValueLengthExceeded { length, limit } => {
                Self::ReturnedValueLengthExceeded(ReturnedValueLengthExceeded { length, limit })
            }
            H::ContractSizeExceeded { size, limit } => {
                Self::ContractSizeExceeded(ContractSizeExceeded { size, limit })
            }
            H::Deprecated { method_name } => Self::Deprecated(Deprecated { method_name }),
            H::ECRecoverError { msg } => Self::ECRecoverError(ECRecoverError { msg }),
            H::AltBn128InvalidInput { msg } => {
                Self::AltBn128InvalidInput(AltBn128InvalidInput { msg })
            }
            H::Ed25519VerifyInvalidInput { msg } => {
                Self::Ed25519VerifyInvalidInput(Ed25519VerifyInvalidInput { msg })
            }
        }
    }
}

#[pyclass(module = "pyonear.error.vm")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum HostErrorFieldless {
    /// String encoding is bad UTF-16 sequence
    BadUTF16,
    /// String encoding is bad UTF-8 sequence
    BadUTF8,
    /// Exceeded the prepaid gas
    GasExceeded,
    /// Exceeded the maximum amount of gas allowed to burn per contract
    GasLimitExceeded,
    /// Exceeded the account balance
    BalanceExceeded,
    /// Tried to call an empty method name
    EmptyMethodName,
    /// IntegerOverflow happened during a contract execution
    IntegerOverflow,
    /// Actions can only be appended to non-joint promise.
    CannotAppendActionToJointPromise,
    /// Returning joint promise is currently prohibited
    CannotReturnJointPromise,
    /// Accessed memory outside the bounds
    MemoryAccessViolation,
    /// VM Logic returned an invalid account id
    InvalidAccountId,
    /// VM Logic returned an invalid method name
    InvalidMethodName,
    /// VM Logic provided an invalid public key
    InvalidPublicKey,
}
hash_enum!(HostErrorFieldless);

quick_struct_vm!(GuestPanic, "Smart contract panicked", panic_msg: String);
quick_struct_vm_u64!(
    InvalidPromiseIndex,
    "``promise_idx`` does not correspond to existing promises",
    promise_idx
);
quick_struct_vm_u64!(
    InvalidPromiseResultIndex,
    "Accessed invalid promise result index",
    result_idx
);
quick_struct_vm_u64!(
    InvalidRegisterId,
    "Accessed invalid register id",
    register_id
);
quick_struct_vm_u64!(IteratorWasInvalidated, "Iterator `iterator_index` was invalidated after its creation by performing a mutable operation on trie", iterator_index);
quick_struct_vm_u64!(
    InvalidReceiptIndex,
    "VM Logic returned an invalid receipt index",
    receipt_index
);
quick_struct_vm_u64!(
    InvalidIteratorIndex,
    "Iterator index ``iterator_index`` does not exist",
    iterator_index
);
quick_struct_vm_method_name!(
    ProhibitedInView,
    "``method_name`` is not allowed in view calls"
);
quick_struct_vm!(
    NumberOfLogsExceeded,
    "The total number of logs will exceed the limit.",
    limit: u64
);
quick_struct_vm_length_limit!(
    KeyLengthExceeded,
    "The storage key length exceeded the limit."
);
quick_struct_vm_length_limit!(
    ValueLengthExceeded,
    "The storage value length exceeded the limit."
);
quick_struct_vm_length_limit!(
    TotalLogLengthExceeded,
    "The total log length exceeded the limit."
);
quick_struct_vm!(
    NumberPromisesExceeded,
    "The maximum number of promises within a FunctionCall exceeded the limit.",
    number_of_promises: u64,
    limit: u64
);
quick_struct_vm!(
    NumberInputDataDependenciesExceeded,
    "The maximum number of input data dependencies exceeded the limit.",
    number_of_input_data_dependencies: u64,
    limit: u64
);
quick_struct_vm!(
    ReturnedValueLengthExceeded,
    "The returned value length exceeded the limit.",
    length: u64,
    limit: u64
);
quick_struct_vm_size_limit!(
    ContractSizeExceeded,
    "The contract size for DeployContract action exceeded the limit."
);
quick_struct_vm_method_name!(Deprecated, "The host function was deprecated.");
quick_struct_vm_msg!(ECRecoverError, "General errors for ECDSA recover.");
quick_struct_vm_msg!(
    Ed25519VerifyInvalidInput,
    "Invalid input to ed25519 signature verification function (e.g. signature cannot be derived from bytes)."
);
quick_struct_vm_msg!(
    AltBn128InvalidInput,
    "Invalid input to alt_bn128 familiy of functions (e.g., point which isn't on the curve)."
);

impl fmt::Display for PrepareError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        write!(f, "{}", PrepareErrorOriginal::from(*self))
    }
}

impl fmt::Display for WasmTrap {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        write!(f, "{}", WasmTrapOriginal::from(*self))
    }
}

impl fmt::Display for MethodResolveError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        write!(f, "{}", MethodResolveErrorOriginal::from(*self))
    }
}

pub(crate) fn get_function_call_error_ser_members(py: Python) -> Vec<&PyType> {
    vec_type_object!(
        py,
        FunctionCallErrorSerFieldless,
        LinkError,
        WasmTrap,
        PyString
    )
}

pub(crate) fn create_vm_mod(py: Python<'_>) -> PyResult<&PyModule> {
    let m = PyModule::new(py, "vm")?;
    add_classes!(
        m,
        HostErrorFieldless,
        GuestPanic,
        InvalidPromiseIndex,
        InvalidPromiseResultIndex,
        InvalidRegisterId,
        IteratorWasInvalidated,
        InvalidReceiptIndex,
        InvalidIteratorIndex,
        ProhibitedInView,
        NumberOfLogsExceeded,
        KeyLengthExceeded,
        ValueLengthExceeded,
        TotalLogLengthExceeded,
        NumberPromisesExceeded,
        NumberInputDataDependenciesExceeded,
        ReturnedValueLengthExceeded,
        ContractSizeExceeded,
        Deprecated,
        ECRecoverError,
        Ed25519VerifyInvalidInput,
        AltBn128InvalidInput
    );
    let host_error_members = vec_type_object!(
        py,
        HostErrorFieldless,
        GuestPanic,
        InvalidPromiseIndex,
        InvalidPromiseResultIndex,
        InvalidRegisterId,
        IteratorWasInvalidated,
        InvalidReceiptIndex,
        InvalidIteratorIndex,
        ProhibitedInView,
        NumberOfLogsExceeded,
        KeyLengthExceeded,
        ValueLengthExceeded,
        TotalLogLengthExceeded,
        NumberPromisesExceeded,
        NumberInputDataDependenciesExceeded,
        ReturnedValueLengthExceeded,
        ContractSizeExceeded,
        Deprecated,
        ECRecoverError,
        Ed25519VerifyInvalidInput,
        AltBn128InvalidInput
    );
    add_union_to_module("HostError", m, py, host_error_members.clone())?;
    let compilation_error_members = vec_type_object!(
        py,
        CodeDoesNotExist,
        PrepareError,
        WasmerCompileError,
        UnsupportedCompiler
    );
    add_union_to_module("CompilationError", m, py, compilation_error_members.clone())?;
    add_classes!(
        m,
        CodeDoesNotExist,
        PrepareError,
        WasmerCompileError,
        UnsupportedCompiler
    );
    add_union!("CacheError", m, py, CacheErrorFieldless, SerializationError)?;
    add_classes!(m, CacheErrorFieldless, SerializationError);
    add_classes!(
        m,
        FunctionCallErrorSerFieldless,
        LinkError,
        MethodResolveError,
        WasmTrap
    );
    let mut function_call_error_ser_members = get_function_call_error_ser_members(py);
    function_call_error_ser_members.extend(compilation_error_members);
    function_call_error_ser_members.extend(host_error_members);
    add_union_to_module(
        "FunctionCallErrorSer",
        m,
        py,
        function_call_error_ser_members,
    )?;
    Ok(m)
}